JavaScript parentElement Property Tutorial

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

What is Element parentElement Property in JavaScript?

The JavaScript Element parentElement property is used to get a reference to the parent element of a 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 parentElement property on the <li> element would return a reference to the <ol> which is its parent element.

JavaScript parentElement Property Syntax:

element.parentElement;

JavaScript parentElement Property Input Value

The property is read-only and so it does not take an input value.

JavaScript parentElement Property Return Value

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

Note: if the target node does not have a parent of type Element-node (for example, the <HTML> element’s parent is not of type Element-node) then the return value of this property will be a null value.

Example: using parentElement Property in JavaScript

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

Leave a Reply