NodeIterator: previousNode() method - Web APIs | MDN
Syntax
Parameters
None.
Return value
A Node representing the node before the current node in the set represented by this NodeIterator, or null if the current node is the first node in the set.
Examples
js
const nodeIterator = document.createNodeIterator(
document.body,
NodeFilter.SHOW_ELEMENT,
{
acceptNode(node) {
return NodeFilter.FILTER_ACCEPT;
},
},
);
currentNode = nodeIterator.nextNode(); // returns the next node
previousNode = nodeIterator.previousNode(); // same result, since we backtracked to the previous node
Specifications
| Specification |
|---|
| DOM # dom-nodeiterator-previousnode |
Browser compatibility
See also
- The interface it belongs to:
NodeIterator.