Node.parentNode read-only property returns the parent of the specified node in the DOM tree.

句法

parentNode = node.parentNode
					

parentNode is the parent of the current node. The parent of an element is an 元素 node, a Document node, or a DocumentFragment 节点。

范例

if (node.parentNode) {
  // remove a node from the tree, unless
  // it's not in the tree already
  node.parentNode.removeChild(node);
}
					

注意事项

Document and DocumentFragment nodes can never have a parent, so parentNode will always return null .

It also returns null if the node has just been created and is not yet attached to the tree.

规范

规范 状态 注释
DOM
The definition of 'Node: parentNode' in that specification.
实时标准

浏览器兼容性

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
parentNode Chrome 1 Edge 12 Firefox 1 IE 5.5 Opera 7 Safari 1.1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: