CKTIS / JavaScript
Node.parentElement — the immediate parent element
Node.parentElement returns the immediate parent of type Element, or null. Unlike parentNode, it never returns a Document or DocumentFragment.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
node.parentElementNode.parentElement is a read-only DOM property, not a method. Reading node.parentElement returns the immediate parent if it is an Element; otherwise it returns null.
It also works on text nodes. It does not search for a more distant ancestor. parentNode can return a Document or DocumentFragment, whereas parentElement returns null in those cases.
Having no parent also means null; check the result before further access. Being disconnected from the document does not rule out an Element parent. This is a Web API, not an ECMAScript language feature; the example requires a DOM environment.
Examples
const parent = document.createElement('section');
const text = document.createTextNode('Hello');
parent.appendChild(text);
console.log(text.parentElement === parent);
console.log(parent.parentElement === null);
const fragment = document.createDocumentFragment();
fragment.appendChild(parent);
console.log(parent.parentNode === fragment);
console.log(parent.parentElement === null);Result
true true true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.