Javascript [Electronic resources] : The Definitive Guide (4th Edition)

David Flanagan

نسخه متنی -صفحه : 844/ 721
نمايش فراداده

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
}