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.

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes129 Yes1 Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes9 Yes ? Yes

1. Only supported on Element.

Specification

See also

Document Tags and Contributors

Last updated by: fscholz,