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 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.

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge Full support 12Firefox Full support 9IE Full support Yes
Notes
Full support Yes
Notes
Notes Only supported on Element.
Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 9Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

Specification

See also

Document Tags and Contributors

Last updated by: GawiSh404,