offline version v3


161 of 264 menu

parentElement property

The parentElement property contains a parent element.

Syntax

element.parentElement;

Example

Let's obtain the parent of the #elem element and display its id:

<div id="parent"> <p id="elem"></p> </div> let elem = document.querySelector('#elem'); let id = elem.parentElement.id; console.log(id);

The code execution result:

'parent'

See also

  • the parentNode property
    that defines a parent node
enru