Java Reference
In-Depth Information
Finally, you use the previousSibling property to move back in your tree to the <h1/> element and
this time change the font to Courier.
if (pElement.previousSibling.nodeType==3)
{
h1Element = pElement.previousSibling.previousSibling
}
else
{
h1Element = pElement.previousSibling
}
h1Element.style.fontFamily = “Courier”;
This is a fairly easy example to follow because you're using the same tree structure you created with
diagrams, but it does show how the DOM effectively creates this hierarchy and that you can move
around within it using script.
Methods of the Node Object
While the Node object's properties enable you to navigate the DOM, its methods provide the completely
different ability to add and remove nodes from the DOM, thus fundamentally altering the structure of
the HTML document. The following table lists these methods.
Methods of Node Objects
Description
appendChild(newNode)
Adds a new node object to the end of the list of child nodes.
This method returns the appended node.
cloneNode(cloneChildren)
Returns a duplicate of the current node. It accepts a Boolean
value. If the value is true, then the method clones the cur-
rent node and all child nodes. If the value is false, only the
current node is cloned and child nodes are left out of the
clone.
hasChildNodes()
Returns true if a node has any child nodes and false
if not.
insertBefore(newNode,
referenceNode)
Inserts a new node object into the list of child nodes before
the node stipulated by referenceNode . Returns the
inserted node.
removeChild(childNode)
Removes a child node from a list of child nodes of the node
object. Returns the removed node.
Search WWH ::




Custom Search