parentElement property

The parentElement property contains a parent element.

Syntax

javascriptelement.parentElement;

Example

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

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

console.log(id);

The code execution result:

javascript'parent'

See also

  • the parentNode property
    that defines a parent node