jQuery remove() Method

Beginner
5 min read
Updated: Oct 2026
4 examples
Live preview

What Is remove()?

.remove([selector]) takes matched elements out of the DOM — the elements themselves and everything inside them (since jQuery 1.0). Bound events and jQuery data are removed too.

Remember
$(".hello").remove()
$("div").remove(".hello")          // filter
$("p").remove(":contains('Hello')")

// delete the element itself
// keep parent, clear children → .empty()
// remove but keep data/events → .detach()
NeedUse
Delete element + children$el.remove()
Clear children only.empty()
Remove but keep data/events.detach()
Filter then delete$el.remove(selector)

How to Use remove()

Select the nodes to delete, optionally filter, then call remove.

  1. Select the element(s) you want to delete.
  2. Optionally pass a selector to narrow that set further.
  3. Call .remove() — nodes leave the document.
  4. jQuery clears associated data and event handlers automatically.
PieceRequired?Role
jQuery collectionYesElements to remove
selectorOptionalFilter which matched items are removed
Return—Same collection (now out of the document)

Pseudocode

Pseudocode
set = matched elements
if selector given:
    set = set filtered by selector

for each element in set:
    clear jQuery data and events
    remove element (and children) from the DOM

return set

// Official idea:
$(".hello").remove()
$("div").remove(".hello")   // same effect here

Cheat Sheet

Keep these facts handy while deleting nodes.

TopicDetail
Syntax.remove([selector])
SincejQuery 1.0
DeletesElement + descendants
Data / eventsCleaned up
vs .empty()Deletes self vs clears children only
vs .detach()Discards vs keeps jQuery state
FilterOptional selector argument

Live Preview

Run official-style remove actions on a tiny demo tree and see which nodes disappear.

Browser demo of .remove() — same idea as the examples below.

Result
Ready — pick an action and run.

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Official Demo: Remove Matched Elements

Delete every element with class hello from the document.

jQuery
// <div class="hello">Hello</div>
// <div class="goodbye">Goodbye</div>
$(".hello").remove();
Try It Yourself

How It Works

  1. Select. $(".hello") finds the Hello div.
  2. Remove. That element leaves the DOM entirely.
  3. Children go too. Anything nested inside would also disappear.
  4. Cleanup. jQuery data and handlers on it are cleared.

Example 2 — Official Demo: Filter With a Selector

Start from all divs, then remove only those that match .hello.

jQuery
// same HTML as Example 1
$("div").remove(".hello");
// same idea as: $("div").filter(".hello").remove();
Try It Yourself

How It Works

  1. Broad select. $("div") matches both siblings.
  2. Filter arg. ".hello" keeps only the Hello div for removal.
  3. Goodbye stays. It did not match the filter.
  4. Same result. Equivalent to $(".hello").remove() here.

Example 3 — Official Demo: :contains Filter

Remove only paragraphs that contain the text Hello.

jQuery
// <p>Hello</p><p>how are you?</p>
$("p").remove(":contains('Hello')");
// analogous to: $("p").filter(":contains('Hello')").remove();
Try It Yourself

How It Works

  1. Select paragraphs. Both <p> elements match first.
  2. Filter text. :contains('Hello') keeps only the first.
  3. Remove that one. The second paragraph remains.
  4. Official note. Same idea as .filter().remove().

Example 4 — remove vs empty

Delete the box itself, or keep the box and clear its children.

jQuery
// <div id="box"><span>Item</span></div>
$("#box").empty();   // <div id="box"></div> remains
$("#box").remove();  // #box is gone from the document
Try It Yourself

How It Works

  1. empty. Children are cleared; the parent shell stays.
  2. remove. The parent itself is deleted from the DOM.
  3. Pick by intent. Clear a list shell → empty; delete a widget → remove.
  4. See also. Need to put it back later? Prefer .detach().

Edge Cases & Pitfalls

Check these before deleting nodes in real pages.

state

Cannot restore data after remove

Handlers and .data() are gone. Use .detach() if you plan to reinsert.

scope

Children are deleted too

Removing a parent removes nested content. To keep the parent, use .empty().

filter

Selector filters the matched set

$("div").remove(".hello") only removes divs that also match .hello.

query

Gone from the document

After remove, a normal selector will not find those nodes again.

Browser Support

.remove() is a core jQuery method (since 1.0). It needs a browser DOM with jQuery loaded.

✓ jQuery 1.0+ · Browsers only

jQuery .remove()

Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery. Not for Node.js without a DOM.

100% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.remove() Browsers

Bottom line: Use .remove() in the browser to delete elements permanently. Prefer .detach() when you need to put them back with data intact.

Performance Notes

ApproachCostBest for
.remove()Low–moderatePermanent deletion + cleanup
.empty()SimilarClearing a container you will reuse
.detach()SimilarTemporary removal with state kept

Prefer one targeted remove over many tiny deletes in a loop when you can. Removing large subtrees also cleans nested jQuery data — that is intentional, not wasted work.

Key Takeaways

  • Role: delete matched elements (and their children) from the DOM.
  • Cleanup: jQuery data and events are removed too.
  • Filter: optional selector narrows what gets deleted.
  • Choose: empty to clear; detach to park; remove to discard.

One line: $el.remove() deletes the element for good — including children, data, and events.

Frequently Asked Questions

.remove() takes matched elements out of the DOM — the elements and everything inside them. It also cleans up bound event handlers and jQuery data. Returns the same jQuery collection. Available since jQuery 1.0.
Both remove nodes from the document. .remove() also discards jQuery data and events. .detach() keeps that state so you can reinsert later. Use remove when nodes will not come back.
.remove() deletes the matched elements themselves. .empty() keeps the matched parents and only clears their children. Use remove to delete a widget; use empty to clear a container shell.
Yes. Pass an optional selector: $('div').remove('.hello') removes only divs that also match .hello. Same idea as .filter(selector).remove().
Yes. Handlers bound with .on() and the internal data cache are cleared to help avoid memory leaks. If you need handlers after removal, use .detach() instead.
The same jQuery collection that was removed. Those nodes are no longer in the document, so you cannot find them again with a normal selector query.

Next: unwrap()

Learn how to remove the parents of matched elements while keeping the children.

unwrap() tutorial →

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.

9 people found this page helpful