The pointerBeforeReferenceNode property of a NodeIterator is a read-only boolean that tells you whether the walk pointer sits before or after the anchor (referenceNode). Learn what true and false mean, how nextNode() updates the flag, and how to pair it with filter—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
Boolean
03
true
Before anchor
04
false
After anchor
05
Pair
referenceNode
06
Status
Baseline widely
Fundamentals
Introduction
A NodeIterator does not only return nodes from nextNode()—it also tracks where the walk is anchored. The read-only pointerBeforeReferenceNode property answers a simple question: is the iterator pointer immediately before the reference node, or immediately after it?
MDN’s idea: after you create an iterator, read nodeIterator.pointerBeforeReferenceNode to inspect that flag. As you call nextNode() or previousNode(), both this boolean and referenceNode can change.
💡
Beginner tip
For everyday loops you often only need nextNode(). Use pointerBeforeReferenceNode when you want to debug iterator position or understand anchor state alongside referenceNode.
Concept
Understanding the pointerBeforeReferenceNode Property
A read-only instance property on NodeIterator that describes iterator position relative to the anchor node.
Returns — a boolean.
true — pointer is before referenceNode.
false — pointer is after referenceNode.
Read-only — updated by iterator movement, not by assignment.
Baseline Widely available on MDN (since April 2018).
Foundation
📝 Syntax
Read the property on a NodeIterator:
JavaScript
nodeIterator.pointerBeforeReferenceNode
Return value
A boolean: true (before anchor) or false (after anchor).
Typical pattern (MDN idea)
JavaScript
const nodeIterator = document.createNodeIterator(
document.body,
NodeFilter.SHOW_ELEMENT,
{ acceptNode: () => NodeFilter.FILTER_ACCEPT },
);
const flag = nodeIterator.pointerBeforeReferenceNode;
// true or false depending on anchor position
NodeIterator.pointerBeforeReferenceNode 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.pointerBeforeReferenceNode
Read-only boolean: true when the iterator pointer is before referenceNode, false when after.
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
pointerBeforeReferenceNodeExcellent
Bottom line: Read this flag with referenceNode to understand where a NodeIterator is anchored in the tree.
Wrap Up
Conclusion
NodeIterator.pointerBeforeReferenceNode tells you whether the walk pointer is before (true) or after (false) the anchor node. Read it with referenceNode to understand iterator state, especially after nextNode() or previousNode().
Expect the flag to change when you call movement methods
Prefer simple nextNode() loops for basic tasks
❌ Don’t
Try to assign a value to pointerBeforeReferenceNode
Confuse it with filter (that screens nodes)
Assume it stays constant during a walk
Rely on it when querySelectorAll is enough
Forget that referenceNode moves with the iterator
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about pointerBeforeReferenceNode
Before or after the anchor.
5
Core concepts
🔗01
Returns
boolean
API
⚙️02
true
before
Position
🔒03
false
after
Position
📄04
+ ref node
pair
Context
🎯05
Baseline
since Apr 2018
Status
❓ Frequently Asked Questions
A read-only boolean. true means the iterator pointer sits before referenceNode; false means it sits after referenceNode.
No. MDN marks it as Baseline Widely available (since April 2018). It is not Deprecated, Experimental, or Non-standard.
No. It is read-only. Call nextNode() or previousNode() to move the iterator; the flag updates automatically.
referenceNode is the anchor node. pointerBeforeReferenceNode tells you whether the walk position is immediately before or after that anchor.
Yes. Moving forward with nextNode() (or backward with previousNode()) updates both referenceNode and this boolean as the iterator advances.
Usually not for simple walks. It helps when debugging iterator state or building advanced traversal logic that depends on exact anchor position.
Did you know?
MDN’s sample reads nodeIterator.pointerBeforeReferenceNode right after creation. The interesting part is watching it change as you call nextNode() and previousNode()—together with referenceNode.