TreeWalker: root property

The TreeWalker.root read-only property returns the node that is the root of what 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

desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
root

See also