English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
parentNode只读属性返回指定的节点的父节点,作为节点对象。
如果指定的节点没有父节点,则此属性返回null。
node.parentNode
var x = document.querySelector("#para").parentNode.nodeName;Test See‹/›
All browsers fully support the parentNode property:
Property | |||||
parentNode | Yes | Yes | Yes | Yes | Yes |
Return Value: | A Node object representing the parent node of the specified node; if the node has no parent node, it isnull |
---|---|
DOM Version: | DOM Level1 |
Click the <p> element to hide its parent node (<div>):
<div> <p onclick="this.parentNode.style.display='none';">Click me</p> </div>Test See‹/›
HTML DOM Reference:node.childNodes property
HTML DOM Reference:node.firstChild property
HTML DOM Reference:node.lastChild property
HTML DOM Reference:node.nextSibling property
HTML DOM Reference:node.previousSibling property
HTML DOM Reference:node.nodeName property