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.
html
<!doctype html> < html > < head > < meta charset="utf-8"> < title >HTML DOM Node getRootNode() method</ title > </ head > < body > < h1 >w3wiki</ 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 54 and above
- Edge 79 and above
- Firefox 53 and above
- Safari 10.1 and above
- Opera 41 and above
- Internet Explorer not supported