HTML DOM TreeWalker root property
The TreeWalker root property returns the root node of the current TreeWalker. This is a read-only property.
Syntax:
rootNode = TreeWalker.root;
Return Value: This property returns the root node of the TreeWalker.
Example: In this example, we will learn how to get the rootNode of TreeWalker using this property. Here, rootNode is passed as a head node for parameter and it can be verified in console.
html
<!doctype html> < html > < head > < meta charset="utf-8"> < title >HTML DOM TreeWalker root property</ title > </ head > < body > < h1 >w3wiki</ h1 > < p >Click Here to get the root node</ p > < button onclick="get()">Click</ button > </ body > < script > var treeWalker = document.createTreeWalker(document.head); function get(){ node = treeWalker.root; console.log(treeWalker) console.log(node); } </ script > </ html > |
Output:
Before Button Click:
After Button Click:
Supported Browsers:
- Google Chrome 1
- Edge 12
- Firefox 4
- Safari 3
- Opera 9
- Internet Explorer 9