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.


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>
    <meta charset="utf-8">
<title>HTML DOM TreeWalker root property</title>    
    <p>Click Here to get the root node</p>
    <button onclick="get()">Click</button>
        var treeWalker = document.createTreeWalker(document.head);
        function get(){
            node = treeWalker.root;


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 :