Open In App

HTML DOM TreeWalker whatToShow property

Last Updated : 11 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Constant Return Value Constant 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.

HTML




<!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 1
  • Edge 12
  • Firefox 4
  • Safari 3
  • Opera 9
  • Internet Explorer 9

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads