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.


parentElement = node.parentElement

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


if (node.parentElement) { = "red";


Specification Status Comment
The definition of 'parentElement' in that specification.
Living Standard Initial definition.

Browser compatibility

BCD tables only load in the browser

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.

See also