JavaScript parentNode Property Tutorial

In this section, we will learn what the parentNode property is and how to use it in JavaScript.

What is Element parentNode Property in JavaScript?

The JavaScript Element `parentNode` property is used to get a reference to the parent node of the node that is calling this property.

For example, if there’s an <li> element sits as the child of an <ol> element, then calling the parentNode property on the <li> element would return a reference to the <ol> which is its parent node.

JavaScript parentNode Property Syntax:

element.parentNode;

JavaScript parentNode Property Input Value

The parentNode property is read-only and so we can’t assign a value to it.

JavaScript parentNode Property Return Value

The return value of this property is the parent node of the target node that is invoking this property.

Notes:

  • If the target node does not have a parent, then the value of this property will be a null value.
  • Doesn’t matter what type of node the parent is, using this property, we can get a reference to that parent node.

Example: using parentNode Property in JavaScript

See the Pen using parentNode Property in JavaScript by Omid Dehghan (@odchan1) on CodePen.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies