Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Node.rootNode

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

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().

Syntax

rootNode = node.rootNode;

Example

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.

HTML

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

<pre id="output">
</pre>

JavaScript

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;

Notes

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.

Specifications

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

 

ドキュメントのタグと貢献者

 このページの貢献者: Ephys, paesuka, teoli, Sheppy
 最終更新者: Ephys,