The referenceNode property of a NodeIterator returns the anchor Node the iterator is tied to. Learn how it starts at the walk root, updates with nextNode(), pairs with pointerBeforeReferenceNode, and stays meaningful when the DOM changes—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
Node
03
Role
Anchor
04
Writable?
Read-only
05
Moves
next/previous
06
Status
Baseline widely
Fundamentals
Introduction
A NodeIterator walks a DOM subtree, but it always has an anchor: the node stored in referenceNode. That is the node the iterator position is defined relative to.
MDN’s idea: after document.createNodeIterator(...), read nodeIterator.referenceNode to see the anchor. As you call nextNode() or previousNode(), this property updates to reflect the new anchor.
💡
Beginner tip
For simple loops you may only use the value returned by nextNode(). Use referenceNode when you need to inspect or debug where the iterator is anchored in the tree.
Concept
Understanding the referenceNode Property
A read-only instance property on NodeIterator that returns the current anchor Node.
Returns — a Node object.
Read-only — updated by iterator movement, not by assignment.
Initial value — typically the root passed to createNodeIterator.
DOM changes — MDN: iterator stays anchored to this node as nodes are inserted.
Baseline Widely available on MDN (since April 2018).
NodeIterator.referenceNode is marked Baseline Widely available on MDN (since April 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
NodeIterator.referenceNode
Read-only anchor Node for the iterator. Updates when you call nextNode() or previousNode().
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerLimited legacy support for NodeIterator state properties
Legacy partial
referenceNodeExcellent
Bottom line: Read iterator.referenceNode to see which node the walk is anchored to—pair with pointerBeforeReferenceNode for full state.
Wrap Up
Conclusion
NodeIterator.referenceNode is the anchor node for the walk. It starts at the root you pass to createNodeIterator, updates as you move with nextNode() or previousNode(), and pairs naturally with pointerBeforeReferenceNode.
Use nextNode() return value for simple collection loops
Remember the initial anchor is usually the walk root
Distinguish referenceNode from iterator.root
❌ Don’t
Try to assign a new node to referenceNode
Assume it never changes during a walk
Confuse it with the node returned by the last nextNode() in all edge cases without testing
Use NodeIterator when querySelectorAll is enough
Forget MDN’s note about anchoring when the DOM mutates
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about NodeIterator.referenceNode
The anchor node for the walk.
5
Core concepts
🔗01
Returns
Node
API
⚙️02
Read-only
no assign
Rule
🔒03
Starts
at root
Create
📄04
Moves
next/prev
Walk
🎯05
Baseline
since Apr 2018
Status
❓ Frequently Asked Questions
A read-only Node—the anchor node the iterator is currently tied to. It updates as you move the walk with nextNode() or previousNode().
No. MDN marks NodeIterator.referenceNode as Baseline Widely available (since April 2018). It is not Deprecated, Experimental, or Non-standard.
No. It is read-only. Create a new NodeIterator or call nextNode()/previousNode() to change which node is anchored.
Usually the root node you passed to createNodeIterator—the starting anchor before you walk forward.
referenceNode is the anchor Node. pointerBeforeReferenceNode is a boolean saying whether the walk pointer is before or after that anchor.
MDN notes the iterator remains anchored to the reference node as specified by this property when nodes are inserted—useful for live DOM awareness.
Did you know?
MDN notes that as new nodes are inserted, the iterator remains anchored to referenceNode. That makes this property important when you traverse live DOM trees that can change during the walk.