Example 1 — Read SHOW_ELEMENT
Pass a single flag and confirm whatToShow stores it.
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.whatToShow === NodeFilter.SHOW_ELEMENT); // true
console.log(it.whatToShow); // 1 How It Works
- Pass the mask. Second argument is
SHOW_ELEMENT. - Create the iterator. The browser stores that bitmask.
- Read it back.
it.whatToShow === NodeFilter.SHOW_ELEMENT. - See the number.
SHOW_ELEMENTis1(0x1).

