node.parentNode returns the parent Node of a node in the DOM tree, or null if there is no parent (MDN). The parent may be an Element, Document, or DocumentFragment. Use parentElement when you need an Element-only parent.
Status: Baseline Widely available (since July 2015) — not Deprecated, Experimental, or Non-standard. Read-only — change structure with append/remove APIs, not by assigning here.
Remember
node.parentNode
→ parent Node (Element | Document | DocumentFragment | …)
→ or null (no parent)
always null:
document.parentNode
DocumentFragment.parentNode
freshly created, unattached nodes
parentNode → any parent type
parentElement → Element only (else null)
Classic remove:
if (node.parentNode) {
node.parentNode.removeChild(node);
}
Read the parent Node, null-check, then act (inspect, remove, climb).
Select a node (element, text, …).
Read node.parentNode.
If it is not null, use it (e.g. removeChild, inspect nodeName).
Use parentElement when you need Element APIs like style.
Piece
Required?
Role
node
Yes
Any DOM Node
Return
—
Parent Node, or null
Null check
Usually
Avoid calling methods on null
Pseudocode
Pseudocode
parent = node.parentNode
if parent is null:
// detached, or Document / DocumentFragment
else:
// parent may be Element, Document, …
parent.removeChild(node) // classic remove
// vs parentElement:
html.parentNode → document
html.parentElement → null
document.parentNode → null // never has a parent
Reference
Cheat Sheet
Keep these facts handy when walking up the DOM.
Topic
Detail
Syntax
node.parentNode
Returns
Node or null
Mutates?
No — read-only
vs parentElement
Any parent vs Element-only
document / Fragment
Always null (no parent)
Detached node
null (not attached yet)
Standard
Baseline Widely available (since July 2015)
Try it
Live Preview
Read parentNode, compare with parentElement, or run the MDN remove pattern.
Demo
Hi
Starts from #pn-child. Remove uses MDN’s parentNode.removeChild pattern (re-adds after).
Result
Choose an action, then Run…
Code
JavaScript Examples
Short, copy-ready snippets based on MDN Node.parentNode. Use Try It Yourself for a live editor.
Example 1 — Read the Parent Node
A child inside a wrapper reports that wrapper as parentNode.
One parent read is cheap. Prefer node.remove() when you only need to detach and do not care about the parent pointer.
Remember
Key Takeaways
Any parent Node: or null if none.
vs parentElement: any parent type vs Element-only.
Document / Fragment → null: they never have a parent.
Null-check: then removeChild (or use node.remove()).
One line:parentNode is the parent in the tree — any Node type — or null when there is none.
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 MDN 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.