HTML DOM Element parentNode Property

Definition and Usage

parentNode The attribute returns the parent node of the element or node as a Node object.

If the specified node has no parent node, it returns null.

The parentNode property is read-only.

See also:

childNodes property

firstChild property

lastChild property

nextSibling property

previousSibling property

nodeName property

parentElement property

HTML node and element

In HTML DOM(Document Object Model), an HTML document is a collection of nodes that have (or do not have) child nodes.

Noderefers to element nodes, text nodes, and comment nodes.

ElementThe blank space between them is also a text node.

While elements are just element nodes.

Child node and child element

childNodes ReturnsChild node(element nodes, text nodes, and comment nodes).

children ReturnsChild element(not text and comment nodes).

Sibling and element sibling

Siblingare referred to as 'brother' and 'sister'.

Siblingare nodes that have the same parent node (in the same childNodes in the list).

Element siblingare elements that have the same parent element (in the same children in the list).

Example

Example 1

Get the node name of the parent node of "myLI":

let name = document.getElementById("myLI").parentNode.nodeName;

Try it yourself

Example 2

Click on the element (<span>) to hide its parent element:

<div>
  <span onclick="this.parentNode.style.display = 'none';">x</span>
</div>

Try it yourself

Syntax

element.parentNode

or

node.parentNode

Return value

Type Description
Node Parent node
null If the node has no parent node.

Browser support

element.parentnode is a DOM Level 1 (1998) feature.

All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support