TreeWalker: root property

The TreeWalker.root read-only property returns the root Node that the TreeWalker traverses.

Value

A Node object.

Examples

js
const treeWalker = document.createTreeWalker(
  document.body,
  NodeFilter.SHOW_ELEMENT,
  {
    acceptNode(node) {
      return NodeFilter.FILTER_ACCEPT;
    },
  },
  false,
);
root = treeWalker.root; // document.body in this case

Specifications

Specification
DOM Standard
# dom-treewalker-root

Browser compatibility

BCD tables only load in the browser

See also