Node.parentElement read-only property returns the DOM node's parent 元素 ,或 null if the node either has no parent, or its parent isn't a DOM 元素 .

句法

parentElement = node.parentElement
					

parentElement is the parent element of the current node. This is always a DOM 元素 object, or null .

范例

if (node.parentElement) {
    node.parentElement.style.color = "red";
}
					

规范

规范 状态 注释
DOM
The definition of ' parentElement ' in that specification.
实时标准 初始定义。

浏览器兼容性

On some browsers, the parentElement property is only defined on nodes that are themselves an 元素 . In particular, it is not defined on text nodes.

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
parentElement Chrome 1 Edge 12 Firefox 9 IE 9 注意事项
9 注意事项
Only supported on 元素 .
Opera 7 Safari 1.1 WebView Android 1 Chrome Android 18 Firefox Android 9 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: