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 | Status | Comment |
---|---|---|
DOMThe definition of 'parentElement ' in that specification.
|
Living Standard | Initial definition. |
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.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
parentElement
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 9 |
IE Full support 9 Full support 9 Notes' Only supported on |
Opera
Full support 7 |
Safari
Full support 1.1 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android
Full support 9 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- See implementation notes.'
- See implementation notes.
See also
Node.parentElement by Mozilla Contributors is licensed under CC-BY-SA 2.5.