The Node.parentNode property returns the parent of a node in the DOM tree—or null if there is none. Learn parentNode vs parentElement, the classic removeChild pattern, and when Document parents appear.
01
Kind
Read-only property
02
Returns
Node or null
03
May be
Element / Document
04
Document
Always null
05
Classic use
removeChild
06
Status
Baseline widely
Fundamentals
Introduction
parentNode answers: “Who is above me in the tree?” That parent can be an Element (most UI cases), a Document (parent of <html>), or a DocumentFragment.
When you only want a tag parent for styling, prefer parentElement. When you need the full story—including Document—use parentNode.
💡
Beginner tip
The classic remove idiom is if (node.parentNode) node.parentNode.removeChild(node). In modern browsers you can also write node.remove().
Concept
Understanding parentNode
MDN: the read-only parentNode property returns the parent of the specified node in the DOM tree. Document and DocumentFragment nodes never have a parent, so their parentNode is always null. Newly created, unattached nodes also return null.
Parent is usually an Element, Document, or DocumentFragment.
Returns null when there is no parent.
Read-only — mutate the tree with DOM methods.
Foundation
📝 Syntax
JavaScript
const parent = node.parentNode;
if (parent) {
parent.removeChild(node);
}
Return value
A Node that is the parent, or null if there is none.
Compare
⚖️ parentNode vs parentElement
node.parentNode
node.parentElement
Returns
Any parent Node (or null)
Parent Element only (or null)
Child of a div
That div
That div
<html>
document
null
Detached node
null
null
Best for
Full tree / removeChild
UI Element parents
Cheat Sheet
⚡ Quick Reference
Goal
Code
Get parent
node.parentNode
Remove self (classic)
node.parentNode?.removeChild(node)
Remove self (modern)
node.remove()
Element parent only
node.parentElement
<html> parent
document.documentElement.parentNode → document
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about Node.parentNode.
Returns
Node | null
Any parent
Baseline
widely
Since July 2015
Access
read-only
No assignment
Document / fragment
null
Never have parents
Hands-On
Examples Gallery
Examples follow MDN Node.parentNode patterns. Use View Output or Try It Yourself for each case.
📚 Getting Started
Read the parent and remove a node safely.
Example 1 — Read the Parent Node
A child inside a wrapper reports that wrapper as parentNode.
Per MDN, Document and DocumentFragment never have parents. Unattached created nodes also report null until appended.
Example 5 — Climb Including the Document
Walk parentNode until null—you will see #document.
JavaScript
let n = document.getElementById("child");
const path = [];
while (n) {
path.push(n.nodeName);
n = n.parentNode;
}
console.log(path.join(" → "));
// e.g. SPAN → DIV → BODY → HTML → #document
Node.parentNode is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Node.parentNode
Safe for production. Use parentNode for any parent type; use parentElement when you only want an Element.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium & Legacy
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerLong-standing support in legacy IE
Full support
parentNodeExcellent
Bottom line: Use parentNode for full parent access and classic removeChild; use parentElement for Element-only UI parents.
Wrap Up
Conclusion
Node.parentNode returns any parent Node or null. Use it for full tree walks and the classic remove pattern; switch to parentElement when you need an Element for styling APIs.
Expect Document or DocumentFragment to have parents
Confuse DOM Node with the Node.js runtime
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about parentNode
Any parent Node—or null.
5
Core concepts
👆01
Any parent
or null
API
⚖️02
vs parentElement
broader
Compare
🗑️03
removeChild
classic pattern
Pattern
📄04
html → document
#document
Root
🚫05
Doc / fragment
always null
Gotcha
❓ Frequently Asked Questions
The parent Node in the DOM tree — typically an Element, Document, or DocumentFragment — or null if there is no parent.
No. MDN marks Node.parentNode as Baseline Widely available (since July 2015). It is a standard DOM property — not Deprecated, Experimental, or Non-standard.
parentNode returns any parent node type. parentElement returns only an Element, or null when the parent is a Document (or there is no parent).
Document and DocumentFragment nodes never have a parent, so parentNode is always null for them. Newly created, unattached nodes also return null.
Classic pattern: if (node.parentNode) { node.parentNode.removeChild(node); }. Modern code often uses node.remove() instead.
Yes. You read it to find the parent; you change structure with appendChild, removeChild, remove, and similar methods.
Did you know?
MDN’s remove example is still the cleanest mental model for beginners: only ask the parent to remove you if you have a parent. That single if (node.parentNode) guard prevents a common runtime error on detached nodes.