Element.remove() is an instance method that removes the element from its parent in the DOM. Learn the MDN basic example, dismiss-on-click patterns, clearing children, how it compares to removeChild(), and five try-it labs aligned with MDN.
01
Kind
Instance method
02
Action
Detach from parent
03
Args
None
04
Returns
undefined
05
vs removeChild
On element itself
06
Status
Baseline widely
Fundamentals
Introduction
Every element in the DOM sits inside a parent (except the document root). To delete a specific element, you can call element.remove() on that element itself. MDN: it removes the element from its parent node.
If the element has no parent (for example, a node you created with createElement but never inserted), calling remove() does nothing—it does not throw an error.
💡
Beginner tip
remove() deletes this element from the tree. append() adds children inside an element. Opposite directions in the DOM!
Calling el.remove() detaches el from its parent’s child list. The node may still exist in memory if you hold a JavaScript reference to it.
It is an instance method on Element (ChildNode mixin).
Takes no parameters (MDN).
Returns undefined.
If there is no parent node, the call is a no-op (MDN).
Modern alternative to parent.removeChild(child).
MDN: remove is unscopable—unavailable inside a with statement.
Foundation
📝 Syntax
General form of Element.remove (MDN):
JavaScript
remove()
Parameters
Parameter
Description
None
This method takes no arguments (MDN).
Return value
Type
Description
undefined
No return value (MDN).
Common patterns
JavaScript
// MDN example
const element = document.getElementById("div-02");
element.remove();
// Dismiss on click
closeBtn.addEventListener("click", () => {
toast.remove();
});
// Clear all children (each child removes itself)
[...list.children].forEach((item) => item.remove());
Cheat Sheet
⚡ Quick Reference
Goal
Code
Remove one element
el.remove()
Classic parent API
parent.removeChild(el)
Check parent exists
if (el.parentNode) el.remove()
Clear all children
[...parent.children].forEach(c => c.remove())
Return value
undefined
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about Element.remove().
Returns
undefined
Detaches from DOM
Baseline
widely
Since Jul 2015
Args
none
Empty parens
No parent
no-op
Safe call
Compare
📋 remove() vs removeChild()
el.remove()
parent.removeChild(child)
Called on
The element to delete
The parent node
Arguments
None
Child node to remove
Return value
undefined
Removed child node
No parent
No-op (MDN)
Throws NotFoundError
Works on
Element (ChildNode)
Any Node parent
Best for
Modern self-removal
When you need the returned node
MDN: remove() is the element-centric shortcut. removeChild() is the classic parent-centric API.
Hands-On
Examples Gallery
Examples follow MDN Element.remove() patterns. Use View Output or Try It Yourself for each case.
📚 Getting Started
MDN basic removal and dismiss-on-click patterns.
Example 1 — MDN Basic Removal
Remove a specific <div> by id (MDN).
JavaScript
const element = document.getElementById("div-02");
element.remove(); // Removes the div with id "div-02"
console.log(document.getElementById("div-02")); // null
MDN: calling remove() with no parent does nothing. Checking parentNode helps avoid double-remove logic bugs in reusable helpers.
Example 5 — remove() vs removeChild()
Two ways to delete the same element.
JavaScript
const parent = document.getElementById("parent");
const child = document.getElementById("child");
// Modern — on the child
child.remove();
// Classic — on the parent (returns the removed node)
// parent.removeChild(child);
Prefer child.remove() when you already have a reference to the element. Use removeChild() when you need the returned node or work with non-Element parents.
Applications
🚀 Common Use Cases
Closing toasts, alerts, and modal overlays on button click.
Removing list items or table rows after user action.
Clearing a container’s children before re-rendering.
Self-removal in event handlers without finding the parent.
Replacing parent.removeChild(child) with cleaner syntax.
Element.remove() is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.remove()
Safe for production. Use remove() for modern self-removal; use removeChild() when you need the returned node.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerNot supported · Use removeChild
No
remove()Excellent
Bottom line: Use remove() when you have a reference to the element. Pair with append() to add nodes back if needed.
Wrap Up
Conclusion
Element.remove() is the modern way to delete an element from the DOM—call it on the element itself with no arguments. It returns undefined and safely no-ops when there is no parent.
Use remove() when you have a reference to the element
Spread live collections before looping removals
Check parentNode in reusable helpers
Keep a JS reference if you may re-insert the node
Prefer remove() over removeChild for readability
❌ Don’t
Expect a returned node (it is undefined)
Confuse remove() (self) with removeChild (parent)
Loop a live children list without copying first
Assume IE supports remove()
Use with (el) { remove() }—it is unscopable
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.remove()
Delete elements from the DOM cleanly.
5
Core concepts
📝01
Returns
undefined
API
📄02
Args
none
Syntax
🎯03
Target
self
Element
🗑️04
No parent
no-op
Safe
⚡05
vs Child
parent API
Compare
❓ Frequently Asked Questions
It removes the element from its parent node in the DOM. If the element has no parent, calling remove() does nothing (MDN).
No. MDN marks Element.remove() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
None. Call it with empty parentheses: element.remove() (MDN).
Nothing useful — the return value is undefined (MDN).
remove() is called on the element you want to delete. removeChild() is called on the parent and takes the child as an argument.
Not automatically. Once removed, the node is detached. Keep a reference if you need to re-insert it with append() or appendChild().
Did you know?
MDN marks remove() as unscopable: inside a with (node) { … } block, calling remove() throws ReferenceError. Prefer normal method calls—el.remove()—and avoid with entirely in modern code.