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.
Example
if (node.parentElement) { node.parentElement.style.color = "red"; }
Specifications
| Specification |
|---|
| DOM Standard (DOM) # ref-for-dom-node-parentelement① |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
parentElement |
1 |
12 |
9 |
9
Only supported on
Element. |
7
Before Opera 15, this feature was only supported on
Element. |
1.1 |
1 |
18 |
9 |
10.1
Before Opera Android 14, this feature was only supported on
Element. |
1 |
1.0 |
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
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Node/parentElement