JavaScript Element remove() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance method

What You’ll Learn

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

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!

This page is part of JavaScript Element. Related topics include removeChild() and append().

Understanding the remove() Method

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.

📝 Syntax

General form of Element.remove (MDN):

JavaScript
remove()

Parameters

ParameterDescription
NoneThis method takes no arguments (MDN).

Return value

TypeDescription
undefinedNo 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());

⚡ Quick Reference

GoalCode
Remove one elementel.remove()
Classic parent APIparent.removeChild(el)
Check parent existsif (el.parentNode) el.remove()
Clear all children[...parent.children].forEach(c => c.remove())
Return valueundefined
MDN statusBaseline Widely available (since July 2015)

🔍 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

📋 remove() vs removeChild()

el.remove()parent.removeChild(child)
Called onThe element to deleteThe parent node
ArgumentsNoneChild node to remove
Return valueundefinedRemoved child node
No parentNo-op (MDN)Throws NotFoundError
Works onElement (ChildNode)Any Node parent
Best forModern self-removalWhen you need the returned node

MDN: remove() is the element-centric shortcut. removeChild() is the classic parent-centric API.

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
Try It Yourself

How It Works

remove() detaches the element from its parent. The node is no longer in the document, so getElementById returns null.

Example 2 — Dismiss on Click

Remove a toast or alert when the user clicks close.

JavaScript
const toast = document.getElementById("toast");
const closeBtn = document.getElementById("close");

closeBtn.addEventListener("click", () => {
  toast.remove();
  console.log("toast removed");
});
Try It Yourself

How It Works

The close button handler calls remove() on the toast element itself—no need to find the parent first.

📈 Practical Patterns

Clear children, safe removal, and compare with removeChild.

Example 3 — Clear All Children

Remove every child from a list by calling remove() on each.

JavaScript
const list = document.getElementById("list");

[...list.children].forEach((item) => item.remove());

console.log(list.children.length); // 0
Try It Yourself

How It Works

Spread list.children into an array first—live collections shift as you remove nodes. Each child calls remove() on itself.

Example 4 — Safe Remove (Check Parent)

Only remove when the element is still attached to the DOM.

JavaScript
function safeRemove(el) {
  if (el.parentNode) {
    el.remove();
    return true;
  }
  return false;
}

const card = document.getElementById("card");
console.log(safeRemove(card)); // true
console.log(safeRemove(card)); // false (already detached)
Try It Yourself

How It Works

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);
Try It Yourself

How It Works

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.

🚀 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.
  • Pairing with append() for add/remove UI patterns.

🧠 How remove() Detaches an Element

1

Call on the element

You invoke el.remove() on the node you want to delete.

Target
2

Check parent

If parentNode is null, the method does nothing (MDN).

Guard
3

Detach from parent

The browser removes the element from its parent’s child list.

Remove
4

Gone from the DOM tree

The element no longer appears in the page. Keep a JS reference if you need to re-insert it later.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available since July 2015).
  • remove() deletes the element itself—not its children individually.
  • Return value is always undefined.
  • If there is no parent, the call is a safe no-op (MDN).
  • MDN: remove is unscopable (not available inside with).
  • Related: removeChild(), append(), children, JavaScript hub.

Browser Support

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.

Baseline Widely available
Google Chrome Supported · Desktop & Mobile
Yes
Microsoft Edge Supported · Chromium
Yes
Mozilla Firefox Supported · Desktop & Mobile
Yes
Apple Safari Supported · macOS & iOS
Yes
Opera Supported · Modern versions
Yes
Internet Explorer Not 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.

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.

Continue with removeChild(), append(), removeAttribute(), shadowRoot, or the JavaScript hub.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Element.remove()

Delete elements from the DOM cleanly.

5
Core concepts
📄 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.

More Element Topics

Browse Element methods and properties to keep building DOM skills.

removeAttribute() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful