HTML and CSS Reference
In-Depth Information
Table 15.2 Node Properties (continued)
Property
What It Does
nodeName
Returns the name of the node.
nodeType
Returns the type of the node as a number: 1 for element, 2 for attribute, 3 for text.
nodeValue
Sets the value of the node in plain text.
ownerDocument
Returns the root node of the document that contains the node.
parentNode
Returns the element that contains the current node.
previousSibling
Returns the previous child node of an element at the same level as the current child
node.
Table 15.3 Node Methods
Method
What It Does
appendChild(new node)
Appends a new node onto the end of the list of child nodes.
cloneNode(child option)
Makes a clone of a node.
hasChildNodes()
Returns true if the node has children.
insertBefore(new node, current node)
Inserts a new node in the list of children.
removeChild(child node)
Removes a child node from a list of children.
replaceChild(new child, old child)
Replaces an old child node with a new one.
15.3.1 Parents and Children
When looking at the structure of the tree hierarchy, some nodes are above others. A node
above another node is a parent node, and the ones below the parent node are its chil-
dren. See Figure 15.4. Any HTML tags that have both an opening and a closing tag are
always parent nodes, for example, <p> and </p> .
Attributes of an element are considered to be separate nodes in their own right. For
example, the href attribute of the <a> tag is an attribute node, not a child of the <a> tag,
and the title attribute of the <p> tag is also an attribute node. The other type of node is
a text node, which represents the text of an element or an attribute, such as <a
href=“http//w3schools.com” , where the quoted string of text (URL) is a text node.
 
 
Search WWH ::




Custom Search