English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM parentNode 属性

HTML DOM Element Object

parentNode只读属性返回指定的节点的父节点,作为节点对象。

如果指定的节点没有父节点,则此属性返回null

语法:

node.parentNode
var x = document.querySelector("#para").parentNode.nodeName;
Test See‹/›

Browser Compatibility

All browsers fully support the parentNode property:

Property
parentNodeYesYesYesYesYes

Technical Details

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

More Examples

Click the <p> element to hide its parent node (<div>):

<div>
   <p onclick="this.parentNode.style.display='none';">Click me</p>
</div>
Test See‹/›

Related References

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

HTML DOM Element Object