Name
Node
Synopsis
All objects in a document tree (including the Document object
itself) implement the Node interface, which provides the fundamental
properties and methods for traversing and manipulating the tree. The
parentNode property and childNodes[] array allow you to move up
and down the document tree. You can enumerate the children of a
given node by looping through the elements of childNodes[] or by using the firstChild and nextSibling properties (or the lastChild and previousSibling properties, to loop
backward). The appendChild(),
insertBefore(), removeChild(), and replaceChild() methods allow you to modify
the document tree by altering the children of a node.
Every object in a document tree implements both the Node
interface and a more specialized subinterface, such as Element or
Text. The nodeType property
specifies which subinterface a node implements. You can use this
property to test the type of a node before using properties or
methods of the more specialized interface. For example:
varn;// Holds the node we're working withif(n.nodeType==1){// Or use the constant Node.ELEMENT_NODEvartagname=n.tagName;// If the node is an Element, this is the tag name}
Constants
unsigned shortELEMENT_NODE= 1unsigned shortTEXT_NODE= 3unsigned shortPROCESSING_INSTRUCTION_NODE= 7unsigned shortCOMMENT_NODE= 8unsigned shortDOCUMENT_NODE= 9unsigned shortDOCUMENT_TYPE_NODE= 10unsigned shortDOCUMENT_FRAGMENT_NODE= 11These constants are possible values of the
nodeType ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access