この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

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

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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.

Syntax

rootNode = node.rootNode;

Value

A Node object representing the topmost node in the tree.

Example

Running the following line in supporting browsers should return a reference to the HTML/document node:

console.log(document.body.rootNode);

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.

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
DeprecatedNon-standard
Chrome No support NoEdge ? Firefox No support NoIE ? Opera No support NoSafari ? WebView Android No support NoChrome Android No support NoEdge Mobile ? Firefox Android No support NoOpera Android No support NoSafari iOS ? Samsung Internet Android No support No

Legend

No support  
No support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

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

このページの貢献者: wbamberg, ExE-Boss, fscholz, chrisdavidmills, Ephys, pasuk, teoli, Sheppy
最終更新者: wbamberg,