NodeIterator
DOM
DOM
The NodeIterator interface represents an iterator to traverse nodes of a DOM subtree in document order.
A NodeIterator can be created using the Document.createNodeIterator() method, as follows:
const nodeIterator = document.createNodeIterator(root, whatToShow, filter);
Instance properties
This interface doesn't inherit any property.
- NodeIterator.root
- : Returns a Node representing the root node, as specified when the
NodeIteratorwas created. - NodeIterator.whatToShow
- : Returns an
unsigned longbitmask that describes the types of Node to be matched. Non-matching nodes are skipped, but relevant child nodes may be included. - NodeIterator.filter
- : Returns a
NodeFilterused to select the relevant nodes. - NodeIterator.referenceNode
- : Returns the Node to which the iterator is anchored.
- NodeIterator.pointerBeforeReferenceNode
- : Returns a boolean indicating whether or not the
NodeIteratoris anchored before the NodeIterator.referenceNode. Iffalse, it indicates that the iterator is anchored after the reference node.
Instance methods
This interface doesn't inherit any method.
- NodeIterator.detach()
- : This is a legacy method, and no longer has any effect. Previously it served to mark a
NodeIteratoras disposed, so it could be reclaimed by garbage collection. - NodeIterator.previousNode()
- : Returns the previous Node in the document, or
nullif there are none. - NodeIterator.nextNode()
- : Returns the next Node in the document, or
nullif there are none.
Specifications
Browser compatibility
See also
- The creator method: Document.createNodeIterator().
- Related interface: TreeWalker