Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 970 Bytes

index.md

File metadata and controls

48 lines (35 loc) · 970 Bytes
title short-title slug page-type browser-compat
TreeWalker: filter property
filter
Web/API/TreeWalker/filter
web-api-instance-property
api.TreeWalker.filter

{{ APIRef("DOM") }}

The TreeWalker.filter read-only property returns a NodeFilter that is the filtering object associated with the {{domxref("TreeWalker")}}.

When creating the TreeWalker, the filter object is passed in as the third parameter, and its method acceptNode() is called on every single node to determine whether or not to accept it.

Value

A NodeFilter object.

Examples

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • The {{domxref("TreeWalker")}} interface it belongs to.