JavaScript’s Node.parentElement read-only property returns the Node’s parent element or null if the Node does not have a parent element.


An Element object or null if the node does not have a parent element.


Here is an example of using the parentElement property.

Suppose we have the following elements:

 <p>You can do wonderful things with JavaScript.</p>

How can we change the background color of the parent element of the p element with JavaScript?

Well, we can select the p element with the querySelector() method and use the parentElement and style properties:

let p = document.querySelector('p'); = 'orange';

The property returns a CSSStyleDeclaration object containing the inline style of an element. The style can be modified by setting the object’s properties.

Browser compatibility

Internet Explorer
Chrome (Android)
Firefox (Android)
Opera (Android)
Safari (iOS)
Samsung Internet
WebView (Android)
parentElement 1 12 9 9 7 1.1 18 9 10.1 1 1.0 4.4