Javascript Reference
Categories: TreeWalker

javascript TreeWalker firstChild( ), lastChild( ), nextSibling( ), parentNode( ), previousSibling( )

@March 15, 2008, 1:22 a.m.
firstChild( ), lastChild( ), nextSibling( ), parentNode( ), previousSibling( )Firefox/Netscape/NN 7 IE n/a Chrome/Safari/DOM 2  

  

These methods return references to nodes within the hierarchy of items in the TreeWalker object. The parent-descendant relationships between nodes are identical to those of the nodes within the document tree. As you invoke any one of these methods, the TreeWalker's internal pointer moves to a position adjacent to the node's spot within the TreeWalker list. If there is no node meeting the desired reference, the method returns null. This means that you need to verify the existence of the node before reading any property of the node:

if (myTreeWalker.nextSibling( )) {
    var theTag = myTreeWalker.currentNode.tagName;
}
 

If you reference a property of a null reference directly (myTreeWalker.nextSibling( ).tagName, for example), a reference error results.

 
Parameters

None.

 
Returned Value

Reference to a document tree node.


Powered by Linode.