NodeIterator.filter is a read-only property that returns the NodeFilter used to screen nodes — the same object (or callback) you passed as the third argument to createNodeIterator() (see MDN).
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use iterator.filter. Start with this line.
JavaScript
iterator.filter
Call
What it does
iterator.filter
Primary signature.
Built into the browser. Read iterator.filter on a NodeIterator — no import required.
Library declarations
JavaScript
iterator.filter
Parameters
Parameter
Description
filter at create
Optional. Custom screening; omit → usually null
acceptNode(node)
Required. Returns FILTER_ACCEPT or reject/skip
Return Value
Return Value
Description
*
NodeFilter or null
JavaScript Examples
Example 1 — Read filter After Creation
MDN idea: pass a filter object, then read it back from the iterator.
Build a selective filter. Only H1 nodes are accepted.
Grab one target.querySelector("h1") finds a heading.
Call acceptNode yourself. Same method the iterator uses during walks.
Compare the constant. Result equals FILTER_ACCEPT for that h1.
Compatibility
Browser Support
NodeIterator.filter is Baseline Widely available (MDN: across browsers since July 2015). Safe to use without a polyfill in modern teaching and production code.
✓ Baseline · Widely available
NodeIterator.filter
Read-only NodeFilter used to screen nodes during createNodeIterator walks. Available in all major browsers.
98%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
NodeIterator.filterExcellent
Bottom line: Use freely in modern apps. Prefer querySelectorAll for simple CSS matches; use filter when you need document-order walks with custom accept/reject logic.
Frequently Asked Questions
A read-only NodeFilter — the same filter passed as the third argument to document.createNodeIterator(). It exposes acceptNode(node) to screen nodes during traversal. If you omitted the filter, filter is usually null.
No. MDN marks NodeIterator.filter as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. filter is read-only. Create a new NodeIterator with a different filter if you need different screening rules.
Return NodeFilter.FILTER_ACCEPT to include a node, or NodeFilter.FILTER_REJECT / FILTER_SKIP to leave it out. For NodeIterator, FILTER_REJECT and FILTER_SKIP are equivalent (MDN).
whatToShow is a bitmask of node types (elements, text, etc.). filter is a custom acceptNode callback for finer control — for example only paragraphs with a certain class.
Use querySelectorAll for simple CSS matches. Use createNodeIterator with a filter when you need document-order walks with custom accept/reject logic.