JavaScript NodeIterator pointerBeforeReferenceNode Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

NodeIterator.pointerBeforeReferenceNode is a read-only boolean. Per MDN, true means the walk pointer is before referenceNode; false means it is after that anchor.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use iterator.pointerBeforeReferenceNode. Start with this line.

JavaScript
iterator.pointerBeforeReferenceNode
CallWhat it does
iterator.pointerBeforeReferenceNodePrimary signature.

Built into the browser. Read iterator.pointerBeforeReferenceNode on a NodeIterator — no import required.

Library declarations
JavaScript
iterator.pointerBeforeReferenceNode

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*true / false

JavaScript Examples

Example 1 — Read the Flag on Create

MDN idea: after createNodeIterator, read pointerBeforeReferenceNode.

JavaScript
const root = document.createElement("div");
root.innerHTML = "<span>A</span>";

const it = document.createNodeIterator(
  root,
  NodeFilter.SHOW_ELEMENT,
  { acceptNode: () => NodeFilter.FILTER_ACCEPT }
);

console.log(it.pointerBeforeReferenceNode); // true
console.log(it.referenceNode === root);     // true
Try It Yourself

How It Works

  1. Create a small tree. A root div with one child.
  2. Build the iterator. Pass that root to createNodeIterator.
  3. Read the flag. Before any walk, it is usually true (before the anchor).
  4. Confirm the anchor. referenceNode equals root.

Example 2 — After nextNode() and previousNode()

A forward step sets the flag to false; a backward step sets it to true.

JavaScript
const root = document.createElement("div");
root.innerHTML = "<span>A</span><span>B</span>";

const it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT);

it.nextNode(); // DIV
console.log(it.pointerBeforeReferenceNode); // false

it.previousNode(); // DIV
console.log(it.pointerBeforeReferenceNode); // true
Try It Yourself

How It Works

  1. Step forward. nextNode() returns the first match (often the root).
  2. Flag becomes false. The pointer now sits after that node.
  3. Step backward. previousNode() returns to the same node.
  4. Flag becomes true. The pointer now sits before that node again.

Example 3 — Pair with referenceNode

Read both properties together for a full position snapshot.

JavaScript
const root = document.createElement("div");
root.innerHTML = "<span>A</span>";

const it = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT);

function snap(label) {
  console.log(
    label,
    it.referenceNode.nodeName,
    it.pointerBeforeReferenceNode
  );
}

snap("create");   // DIV true
it.nextNode();
snap("after next"); // DIV false
it.nextNode();
snap("child");    // SPAN false
Try It Yourself

How It Works

  1. Snapshot helper. Logs the anchor name and the before/after flag.
  2. On create. Anchor is DIV, flag is true.
  3. First next. Still on DIV, but flag is now false.
  4. Second next. Anchor moves to SPAN; flag stays false.

Browser Support

NodeIterator.pointerBeforeReferenceNode is Baseline Widely available (MDN: across browsers since April 2018). Safe to use without a polyfill in modern teaching and production code.

✓ Baseline · Widely available

pointerBeforeReferenceNode

Read-only boolean: true when the iterator pointer is before referenceNode, false when after.

98% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
pointerBeforeReferenceNode Excellent

Bottom line: Use freely in modern browsers. Pair with referenceNode when you need a full position snapshot.

Frequently Asked Questions

A read-only boolean. true means the iterator pointer sits before referenceNode; false means it sits after referenceNode (MDN).
No. MDN marks NodeIterator.pointerBeforeReferenceNode as Baseline Widely available (across browsers 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 pointer is immediately before or after that anchor.
Typically true — the pointer starts before the initial referenceNode (usually the root).
A successful nextNode() leaves the pointer after the returned node (false). A successful previousNode() leaves it before the returned node (true).

Next: referenceNode

Learn the moving anchor Node that pairs with this before/after flag.

referenceNode property →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful