Get the node name of the parent node of "myLI":
let name = document.getElementById("myLI").parentNode.nodeName;
Try it Yourself »
Click on an element (<span>) to hide its parent:
<div>
<span onclick="this.parentNode.style.display = 'none';">x</span>
</div>
Try it Yourself »
The parentNode
property returns the parent node of an element or node.
The parentNode
property is read-only.
In the HTML DOM (Document Object Model), an HTML document is a collection of nodes with (or without) child nodes.
Nodes are element nodes, text nodes, and comment nodes.
Whitespace between elements are also text nodes.
Elements are only element nodes.
childNodes returns child nodes (element nodes, text nodes, and comment nodes).
children returns child elements (not text and comment nodes).
Siblings are "brothers" and "sisters".
Siblings are nodes with the same parent (in the same childNodes list).
Element Siblings are elements with the same parent (in the same children list).
element.parentNode
node.parentNode
Type | Description |
Node | The parent node.null if the node has no parent. |
element.parentnode
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!