JavaScript node.getRootNode() Method

You are Here:

JavaScript node.getRootNode() Method

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


HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); console.log(x.getRootNode()); </script> </body> </html>



Parameter Values

Optional A Boolean that indicates whether the shadow root should be returned.
If true, the shadow root should be returned.
If false, the shadow root should not be returned. Default value.

Return Values

ObjectReturns the context object's root.

node.getRootNode() with Options


HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point">Main Element</p> <script> var x = document.getElementById("point"); var node = document.createElement("h2"); var shadowRoot = node.attachShadow({mode: "open"}); shadowRoot.innerHTML = '<div id="myShadowChild">content</div>'; var shadowChild = shadowRoot.getElementById("myShadowChild"); console.log(x.getRootNode()); console.log(shadowChild.getRootNode({composed: false})); </script> </body> </html>


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author