过时
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.

重要 : For compatibility reasons, this property has been replaced by the Node.getRootNode() 方法。

Node.rootNode 只读特性返回 节点 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.

句法

rootNode = node.rootNode;
					

A 节点 object representing the topmost node in the tree.

范例

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

console.log(document.body.rootNode);
					

注意事项

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.

Whitespace in the DOM and W3C DOM 3 FAQ: Why are some Text nodes empty? 了解更多信息。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
rootNode 弃用 非标 Chrome No Edge No Firefox No IE ? Opera No Safari ? WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS ? Samsung Internet Android No

图例

不支持

不支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

元数据

  • 最后修改: