Web APIs

Node.parentElement

Try the free JavaScript compiler

Return the parent only if it is an element; detached nodes and children of document fragments can have no parent element. Example console output: true true.

Formal Syntax & Structure

javascript syntaxjavascript
node.parentElement

Return Value

Element or null

Parent element or null.

Working Example

Example Snippetjavascript
const frag=document.createDocumentFragment(); const p=document.createElement("p"); frag.append(p); console.log(p.parentNode===frag,p.parentElement===null);
JavaScript Reference