Skip to content
Related Articles

Related Articles

HTML DOM Node.getRootNode() method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 14 Jul, 2020

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


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.

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


Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!