Open In App

HTML DOM TreeWalker root property

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

The TreeWalker root property returns the root node of the current TreeWalker. This is a read-only property.

Syntax:

rootNode = TreeWalker.root;

Return Value: This property returns the root node of the TreeWalker.

Example: In this example, we will learn how to get the rootNode of TreeWalker using this property. Here, rootNode is passed as a head node for parameter and it can be verified in console.

html




<!doctype html>
<html>
<head>
    <meta charset="utf-8">
<title>HTML DOM TreeWalker root property</title>   
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <p>Click Here to get the root node</p>
    <button onclick="get()">Click</button>
</body>
<script>
        var treeWalker = document.createTreeWalker(document.head);
        function get(){
            node = treeWalker.root;
            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
Previous
Next
Share your thoughts in the comments

Similar Reads