Name
NodeIterator.nextNode( ) — iterate to the next node
Availability
DOM Level 2 Traversal
Synopsis
Node nextNode( ) throws DOMException;
Returns
The next node in the sequence of nodes represented by this
NodeIterator, or null
if the last node has already
been returned.
Throws
If this method is called after a call to detach( )
, it throws a DOMException with a code
of INVALID_STATE_ERR
.
Description
This method iterates forward through the sequence of nodes represented by this NodeIterator. If this is the first time it is called for a NodeIterator, it returns the first node in the sequence. Otherwise, it returns the node that follows the one that was previously returned.
Example
// Create a NodeIterator to represent all elements in the document body var ni = document.createNodeIterator(document.body, NodeFilter.SHOW_ELEMENT, null, false); // Loop forward through all nodes in the iterator for(var e = ni.nextNode( ); e != null; e = ni.nextNode( )) { // Do something with element e }
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.