This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The Node.rootNode read-only property returns a Node object representing the topmost node in the tree, or the current node if it's the topmost node in the tree. This is found by walking backward along Node.parentNode until the top is reached.

For compatibility reason, this property has been replaced by the method Node.getRootNode().


rootNode = node.rootNode;


This example constructs a simple DOM tree of elements, then displays information about a specific node followed by the base URI of its root node.


<div id="outer">
  <div id="inner">
    <a id="button" href="go.html">
    <p><em id="me">It's me.</em></p>
    <p>I was wondering if after all these years, you still code in C...</p>

<pre id="output">


let output = document.getElementById("output");

let me = document.getElementById("me");
output.innerHTML += "Element with id 'me': " + me.outerHTML + "<br>";
output.innerHTML += "Root node's base URI: " + me.rootNode.baseURI;


Gecko-based browsers insert text nodes into a document to represent whitespace in the source markup. Therefore a node obtained, for example, using Node.firstChild or Node.previousSibling may refer to a whitespace text node rather than the actual element the author intended to get.

See Whitespace in the DOM and W3C DOM 3 FAQ: Why are some Text nodes empty? for more information.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 48 (48)[1] ? ? ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 48.0 (48)[1] ? ? ?

[1] Not activated by default; it is behind the pref dom.node.rootNode.enabled and  you need to set it to true to activate it.


Specification Status Comment
The definition of 'Node.rootNode' in that specification.
Living Standard Initial definition


Document Tags and Contributors

 Contributors to this page: Ephys, paesuka, teoli, Sheppy
 Last updated by: Ephys,