You are here: Reference > JavaScript > client-side > xml handling > properties > root (NodeIterator, TreeWalker)

root property (NodeIterator, TreeWalker)

Browser support:
Returns the root element that was used to create the NodeIterator or TreeWalker object.
Note: The TreeWalker and NodeIterator objects and their root properties are supported in Internet Explorer from version 9.
This property can be set by the first parameter of the createNodeIterator and createTreeWalker methods.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Reference to the root element.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the root property:
    <script type="text/javascript">
        function TestRoot () {
            if (document.createTreeWalker) {
                var walker = document.createTreeWalker (document.body, NodeFilter.SHOW_ALL, null, true);
                alert ("The tag name of the root element: " + walker.root.tagName);
            else {
                alert ("Your browser does not support the createTreeWalker method!");
    <button onclick="TestRoot ()">Test root property</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content