Web APIs
Node.parentElement
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.parentElementReturn 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);