Open In App

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)

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:

Article Tags :