Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM TreeWalker root property

  • Last Updated : 07 Jul, 2020

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

Syntax:

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

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.






<!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
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer
My Personal Notes arrow_drop_up
Recommended Articles
Page :