DOM Node.parentElement Property
The parentElement property returns the element that contains a node, or null.
Description
The read-only parentElement property returns the node's parent if it is an element, otherwise null. The only practical difference from parentNode is at the top of the tree: the <html> element's parentElement is null, because its parent is the document.
It's often used to walk up from an event target to a container, although closest() is usually shorter when you can describe the container with a selector. For nodes inside a document fragment, the top-level children's parentElement is null, because a fragment isn't an element.
Text nodes have a parentElement too, which is handy when working with selections or ranges, where you start from a text node and need the element that contains it.
Syntax
node.parentElementValue
The parent element, or null if there is none or the parent isn't an element.
Example
Browser Support
The following information will show you the current browser support for the Node.parentElement property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





