Skip to content
Related Articles

Related Articles

HTML DOM Node.getRootNode() method
  • Last Updated : 14 Jul, 2020
GeeksforGeeks - Summer Carnival Banner

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.






<!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>

Output:

Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :