The Node.parentElement read-only property returns the DOM node's parent Element, or null if the node either has no parent, or its parent isn't a DOM Element.

Syntax

parentElement = node.parentElement

parentElement is the parent element of the current node. This is always a DOM Element object, or null.

Example

if (node.parentElement) {
    node.parentElement.style.color = "red";
}

Browser compatibility

On some browsers, the parentElement property is only defined on nodes that are themselves an Element. In particular, it is not defined on text nodes.

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) 9.0 (9.0) (Yes) (only on Element) (Yes) (only on Element) (Yes)
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? (Yes) 9.0 (9.0) ? ? ?

Specification

See also

Document Tags and Contributors

 Last updated by: abbycar,