jQuery remove() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DOM

Definition

.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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$(".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()
CallWhat it does
jQuery collectionElements to remove
selectorFilter which matched items are removed
ReturnSame collection (now out of the document)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the element(s) you want to delete.
Step 2Optionally pass a selector to narrow that set further.
Step 3Call .remove() — nodes leave the document.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

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.

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.

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.

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: text() Method — Get or Set Plain Text

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

text() Method — Get or Set Plain Text tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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