Node.removeChild(child) removes a child node from the parent and returns that node (MDN). It leaves the DOM tree, but a kept reference can still be reused later.
Baseline · Widely available: not Deprecated, Experimental, or Non-standard (since about July 2015).
Errors:NotFoundError if child is not a child of that parent; TypeError if child is null (MDN).
Remember
parent.removeChild(child) → removed child node
kept reference → still in memory, reusable
listeners preserved (unlike cloneNode)
MDN patterns:
parent.removeChild(child)
child.parentNode.removeChild(child)
while (el.firstChild) el.removeChild(el.firstChild)
Call it on the parent, pass the child, optionally keep the return value to reinsert later.
Get the parent and the child that belongs to it.
Call parent.removeChild(child).
Store the return value if you need to reuse the node.
Or use child.parentNode.removeChild(child) when you only have the child.
Piece
Required?
Role
Receiver parent
Yes
Current parent of child
child
Yes (not null)
Node to remove
Return value
—
The same removed node
Pseudocode
Pseudocode
if child is null:
throw TypeError
if child.parent is not this node:
throw NotFoundError
detach child from this parent
return child // still in memory if referenced
Reference
Cheat Sheet
Keep these facts handy when removing nodes from the tree.
Topic
Detail
Syntax
parent.removeChild(child)
Returns
The removed child
In DOM after?
No — unless you reappend it
Listeners
Preserved on the returned node
NotFoundError
Not a child of that parent
TypeError
child is null
Clear all
while (el.firstChild) el.removeChild(el.firstChild)
Status (MDN)
Baseline Widely available
Try it
Live Preview
Remove a child, clear all children, use the parentNode pattern, or reappend a kept reference.
Browser demo of Node.removeChild() — detach, clear, or reuse the returned node.
Result
Loading…
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Basic Remove (MDN)
Remove a child from a known parent and keep the return value.
One line:parent.removeChild(child) takes a node out of the tree and hands it back for reuse or discard.
Frequently Asked Questions
It removes a child node from the parent and returns that removed node. The node leaves the DOM; if you keep a reference it still exists in memory and can be reused (MDN).
No. MDN marks it Baseline Widely available (since about July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes. Unlike Node.cloneNode(), the returned node preserves its EventListener objects (MDN).
NotFoundError if the node is not a child of that parent. TypeError if the child argument is null.
Use child.parentNode.removeChild(child) after checking that parentNode exists (MDN pattern).
For modern code, element.remove() is often simpler when you already have the child. removeChild remains useful when you work from the parent or need the returned node.