The whatToShow property of a NodeIterator returns a read-only bitmask of node types the iterator will consider. Learn how it mirrors the second argument to createNodeIterator, how NodeFilter.SHOW_ELEMENT and SHOW_TEXT change what you see, and how it works with filter—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
unsigned long
03
Bitmask
NodeFilter flags
04
Set at
createNodeIterator
05
vs filter
type vs custom
06
Status
Baseline widely
Fundamentals
Introduction
When you call document.createNodeIterator(root, whatToShow, filter), the second argument tells the browser which node types to include in the walk—elements, text nodes, comments, and more. The iterator stores that value on its read-only whatToShow property.
Think of whatToShow as a coarse pre-filter. It runs before your custom filteracceptNode() logic. If a node type is not in the bitmask, the iterator skips it entirely.
💡
Beginner tip
Start with NodeFilter.SHOW_ELEMENT when you only want tags like <p> and <span>. Use NodeFilter.SHOW_TEXT when you care about text content inside elements.
Concept
Understanding the whatToShow Property
A read-only instance property on NodeIterator that returns a non-negative integer representing a bitmask of NodeFilter constants.
Returns — an unsigned long (bitmask).
Read-only — set at creation, never changes.
Source — second argument to createNodeIterator.
Combine flags — use bitwise OR, e.g. SHOW_ELEMENT | SHOW_TEXT.
Default — NodeFilter.SHOW_ALL when omitted.
Baseline Widely available on MDN (since July 2015).
NodeIterator.whatToShow 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.whatToShow
Read-only bitmask of node types the iterator considers—set as the second argument to createNodeIterator.
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.whatToShowExcellent
Bottom line: iterator.whatToShow mirrors the NodeFilter mask you pass to createNodeIterator—it never changes during the walk.
Wrap Up
Conclusion
NodeIterator.whatToShow is the read-only bitmask that controls which node types an iterator considers. Set it as the second argument to createNodeIterator, combine flags with bitwise OR, and pair it with filter for finer control.
Forget that text nodes are separate from element nodes
Assume changing the mask later without creating a new iterator
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about NodeIterator.whatToShow
The node-type bitmask for DOM walks.
5
Core concepts
🔗01
Returns
bitmask
API
⚙️02
Fixed
at create
Rule
🔒03
SHOW_*
NodeFilter
Flags
📄04
vs filter
type mask
Compare
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
A read-only non-negative integer (unsigned long)—a bitmask of NodeFilter constants that tells the iterator which node types to consider during traversal.
No. MDN marks NodeIterator.whatToShow as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. whatToShow is read-only. Create a new NodeIterator with a different second argument if you need another node-type mask.
whatToShow is a coarse bitmask of node kinds (elements, text, comments, etc.). filter is a custom acceptNode function for finer screening—e.g. only certain elements.
When you omit the second argument to createNodeIterator, the default is NodeFilter.SHOW_ALL (0xFFFFFFFF), which includes every node type the iterator can visit.
Use bitwise OR with NodeFilter constants, e.g. NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT. The stored whatToShow property reflects that combined mask.
Did you know?
MDN’s example combines SHOW_ELEMENT | SHOW_COMMENT | SHOW_TEXT, then tests the mask with bitwise &. That pattern lets you inspect an iterator and know whether comments are in scope before you walk.