HTML DOM TreeWalker filter Property

The TreeWalker filter property returns a Filter node that is a filtering object associated with the created TreeWalker. It is a read-only property.

When creating the TreeWalker, the filter node or object is passed as the third parameter which is retrieved using this property.

Syntax:

nodeFilter = treeWalker.filter;

Return Value: This property returns a node filter of the TreeWalker.

Example: In this example, we will get the node filter of the TreeWalker using this property.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!doctype html>
<html>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <p>Click Here to get the filter node</p>
  
    <button onclick="get()">Click</button>
  
    <script>
        var treeWalker = document.createTreeWalker
            (document.head, NodeFilter.SHOW_ELEMENT,
                {
                    acceptNode: function (node) 
                    { return NodeFilter.FILTER_ACCEPT; }
                },
                false
            );
        function get() {
            node = treeWalker.filter;
            console.log(node);
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Clicking the Button:

  • After Clicking the Button: In console filter, node can be seen.

Supported Browsers: 

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.