W3cubDocs

/DOM

Node.parentElement

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.

JExample

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

Browser compatibilityUpdate compatibility data on GitHub

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.

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes 12 9 Yes
Yes
Only supported on Element.
Yes Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes 9 Yes ? Yes

Specification

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Node/parentElement