HTML DOM Node.getRootNode() method

The getRootNode() method returns the node object’s root node, it optionally also includes the shadow root if it is available.

Syntax:

var rootNode = node.getRootNode(Composed:boolean);

Parameters: Composed:Boolean(optional)

  • Composed: A Boolean that indicates if the shadow root should be returned (false), or a root node beyond shadow root (true).

Return Value: Root node of the object.

Example: This example shows how to get the root node of an object using this method.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
<title>HTML DOM Node getRootNode() method</title>    
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <p>Click to Check</p>
    <button onclick="Check()">Click Here</button>
    <div class="child"></div>
</body>
<script>
    function Check(){
         var child = document.querySelector('.child');
         console.log(child.getRootNode());
        }
</script>
</html>

chevron_right


Output:

Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.