The root property of a NodeIterator returns the fixed root Node of the subtree being traversed. Learn how it matches the first argument to createNodeIterator, how it differs from referenceNode, and why it never changes during a walk—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
Node
03
Fixed?
Yes
04
Set at
createNodeIterator
05
vs ref
referenceNode
06
Status
Baseline widely
Fundamentals
Introduction
When you call document.createNodeIterator(root, ...), you choose where the walk begins and ends. The iterator remembers that node on its read-only root property—the top of the subtree it is allowed to traverse.
MDN’s classic example: if you pass document.body, then nodeIterator.root is document.body. That value stays the same even after you call nextNode() many times.
💡
Beginner tip
root is the fixed boundary; referenceNode is the moving anchor. On a new iterator they may start equal, but only referenceNode changes as you walk.
Concept
Understanding the root Property
A read-only instance property on NodeIterator that returns the node passed as the first argument to createNodeIterator.
Returns — a Node object.
Read-only — never changes for this iterator.
Scope — defines the subtree the iterator can traverse.
Not the same asreferenceNode, which moves during walks.
Baseline Widely available on MDN (since July 2015).
NodeIterator.root is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
NodeIterator.root
Read-only Node that is the root of what the NodeIterator traverses—set at createNodeIterator time.
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 ExplorerSupported on NodeIterator (legacy DOM)
Legacy OK
NodeIterator.rootExcellent
Bottom line: iterator.root always points at the node you passed to createNodeIterator—it never moves during the walk.
Wrap Up
Conclusion
NodeIterator.root is the fixed subtree root you pass to createNodeIterator. It never moves during a walk, unlike referenceNode. Use it to confirm which part of the DOM an iterator covers.
Always use document.body when a smaller root works
Assume root changes during traversal
Forget that each iterator has its own fixed root
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about NodeIterator.root
The fixed subtree boundary.
5
Core concepts
🔗01
Returns
Node
API
⚙️02
Fixed
never moves
Rule
🔒03
= create arg
first param
Create
📄04
vs ref
moving anchor
Compare
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
A read-only Node—the root of the subtree the iterator traverses. It is the node you passed as the first argument to document.createNodeIterator().
No. MDN marks NodeIterator.root as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. root is read-only and stays fixed for the life of the iterator. Create a new NodeIterator with a different root if you need another subtree.
root is the fixed walk boundary set at creation. referenceNode is the moving anchor that updates when you call nextNode() or previousNode().
No. Walking the tree updates referenceNode and pointerBeforeReferenceNode, but root always points at the original root node.
Pass the smallest subtree you need—e.g. document.getElementById('list') instead of document.body—to limit the walk and keep examples easy to follow.
Did you know?
MDN’s example sets root = nodeIterator.root and gets document.body. That value never changes—even when referenceNode moves forward through child elements.