NodeIterator.nextNode() returns the next node in the iterator’s set and advances the position (MDN). The first call returns the first node. When nothing remains, it returns null.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call iterator.nextNode. Start with this line.
JavaScript
iterator.nextNode()
Call
What it does
iterator.nextNode()
Primary signature.
iterator.nextNode(...)
Call with the arguments your case needs.
Built into the browser. Call nextNode(...) on a NodeIterator — no import required.
Library declarations
JavaScript
iterator.nextNode()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Next Node, or null
JavaScript Examples
Example 1 — First Call
The first nextNode() returns the first node in the set.
NodeIterator.nextNode() is marked Baseline Widely available on MDN (since July 2015). DOM API — not a Node.js built-in.
✓ Baseline · Widely available
nextNode()
Walk forward through filtered DOM nodes across modern browsers. Stop when the method returns null.
98%Core tag support
Chrome1+
Full support
Edge12+
Full support
Firefox1+
Full support
Safari3+
Full support
Opera✓
Full support
HTML element100% supported
Bottom line: Safe for production. Create a NodeIterator, call nextNode() until null, and skip deprecated detach().
Frequently Asked Questions
The next node in document order within the iterator’s set, or null when no nodes remain. The first call returns the first node in the set.
No. MDN marks NodeIterator.nextNode() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
When you have reached the end of the walk — there are no more nodes left after whatToShow and filter screening.
Yes. Each successful call advances the iterator and updates referenceNode (and pointerBeforeReferenceNode).
nextNode() moves forward in document order; previousNode() moves backward. Both return a Node or null at the ends of the walk.
Old specs said detach() could invalidate the iterator and cause INVALID_STATE_ERR. Modern browsers treat detach() as a no-op and usually do not throw — still avoid detach() in new code.