Skip to content
Related Articles

Related Articles

Improve Article

HTML DOM TreeWalker whatToShow property

  • Last Updated : 07 Jul, 2020

The TreeWalker whatToShow property returns an unsigned Integer describing the type of Node that must to be presented. This is a read-only property.

Syntax:

whatToShow = treeWalker.whatToShow;

Return Value: This property returns an unsigned Integer describing the type of Node that must be presented.

following are the possible values of unsigned constant.

ConstantReturn ValueConstant Description
NodeFilter.SHOW_ALL

1



Shows all nodes.
NodeFilter.SHOW_COMMENT

128

Shows Comment nodes.
NodeFilter.SHOW_DOCUMENT

256

Shows Document nodes.
NodeFilter.SHOW_DOCUMENT_FRAGMENT

1024

Shows DocumentFragment nodes.
NodeFilter.SHOW_DOCUMENT_TYPE

512

Shows DocumentType nodes.
NodeFilter.SHOW_ELEMENT

1

Shows Element nodes.
NodeFilter.SHOW_PROCESSING_INSTRUCTION

64

Shows ProcessingInstruction nodes.
NodeFilter.SHOW_TEXT

4

Shows Text nodes.

Example: This example has NodeFilter.FILTER_ACCEPT as node filter and hence returns whatToShow value respectively.






<!doctype html>
<html>
<head>
    <meta charset="utf-8">
<title>HTML DOM TreeWalker whatToShow property</title>    
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <p>Click Below</p>
    <button onclick="get()">Click</button>
</body>
<script>
        var treeWalker = 
document.createTreeWalker(document.head,NodeFilter.SHOW_DOCUMENT_TYPE,
        { acceptNode: function(node) {
          return NodeFilter.FILTER_ACCEPT; } },
    false
);
        function get(){
            node = treeWalker.whatToShow;
            console.log(treeWalker)
            console.log(node);
        }
</script>
</html>

Output:

Before Button Click:

After Button Click:

Supported Browsers:

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

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :