jQuery .remove() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM methods

What You’ll Learn

The .remove() method deletes matched elements from the DOM permanently — the nodes themselves and all descendants are gone, and jQuery cleans up associated data and event handlers. This tutorial covers syntax and optional selector filter since 1.0, comparisons with .detach() and .empty(), the official remove demos, and five practical try-it examples.

01

.remove()

Delete nodes

02

Selector

Filter removal

03

Cleanup

Data & events

04

vs .detach()

Preserve state

05

vs .empty()

Keep parent

06

Since 1.0

Core API

Introduction

Interactive pages constantly add and delete UI pieces — dismiss a notification, delete a todo row, close a modal, or strip outdated markup after an Ajax update. When an element should leave the document for good, jQuery provides .remove().

Available since jQuery 1.0, .remove() takes matched elements out of the DOM tree entirely. Unlike .empty(), which clears children but keeps the parent, .remove() deletes the matched nodes themselves along with everything nested inside them. Unlike .detach(), which preserves jQuery data and event handlers for reinsertion, .remove() actively cleans up those associations to prevent memory leaks.

Pass an optional selector to filter which elements in the collection are removed. Use .detach() when you plan to reinsert nodes later; use .empty() when you only need to wipe inner content. Browse the jQuery DOM hub for related manipulation methods.

Understanding the .remove() Method

.remove([selector]) removes matched elements from the DOM and returns the same jQuery collection. The nodes are disconnected from their parent and no longer appear on screen. All descendant elements inside removed nodes disappear as well.

jQuery also erases event handlers bound with .on() and clears .data() entries for removed elements. This cleanup is intentional — once removed, those nodes are not expected to return. Pass an optional selector to limit removal to elements in the collection that also match the filter string.

💡
Beginner Tip

$( ".hello" ).remove() deletes the element entirely from the page — not just its text. Compare with .empty(), which would leave an empty tag behind, and .detach(), which removes the node but keeps click handlers for later.

📝 Syntax

jQuery .remove() supports two forms:

Remove all matched elements — since 1.0

jQuery
.remove()
  • Removes every matched element and its descendants from the DOM.
  • Cleans up jQuery data and event handlers on removed nodes.

Remove with selector filter — since 1.0

jQuery
.remove( selector )
  • selector — only elements in the collection that also match are removed.
  • Equivalent to .filter( selector ).remove() in one call.

Return value

  • Returns the same jQuery collection that was removed.
  • Removed elements are no longer in the document — re-querying by ID may fail.

Official remove patterns

The jQuery API documentation includes two button-click demos:

jQuery
$( "button" ).on( "click", function() {
  $( "p" ).remove();
} );
jQuery
$( "button" ).on( "click", function() {
  $( "p" ).remove( ":contains('Hello')" );
});

⚡ Quick Reference

GoalCode
Delete matched elements$("#temp").remove()
Remove with selector filter$("div").remove(".hello")
Remove by text content$("p").remove(":contains('Hello')")
Remove clicked list item$(this).closest("li").remove()
Clear children only (keep parent)$("#container").empty()
Stash nodes for reinsertionvar stash = $("#panel").detach()

📋 .remove() vs .detach() vs .empty()

Three related DOM removal APIs — pick the right deletion strategy.

.remove()
discard

Delete matched elements from DOM; jQuery cleans up data and event handlers permanently

.detach()
keep data

Remove matched elements from DOM; preserve jQuery data and events for reinsertion

.empty()
children

Remove all child nodes inside matched elements; parent stays in DOM

Examples Gallery

Examples 1–5 follow the official jQuery API documentation and common production patterns. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demos and selector-filter patterns.

Example 1 — Official Demo: Remove All Paragraphs

Button click permanently deletes every paragraph from the DOM — tags and content are gone.

jQuery
$( "button" ).on( "click", function() {
  $( "p" ).remove();
} );
Try It Yourself

How It Works

.remove() disconnects each matched element from its parent. The paragraph nodes are destroyed along with any nested markup and jQuery event handlers bound to them.

Example 2 — Official Demo: Remove With Selector Filter

Delete only paragraphs containing “Hello” — other paragraphs stay on the page.

jQuery
$( "button" ).on( "click", function() {
  $( "p" ).remove( ":contains('Hello')" );
});
Try It Yourself

How It Works

The optional selector argument filters the jQuery collection before removal. Only elements that match both the original selector and the filter string are deleted. This is cleaner than chaining .filter() and .remove() separately.

📈 Practical Patterns

Detach comparison, list deletion, and dismissible UI widgets.

Example 3 — .remove() Cleans Up Data vs .detach()

After .remove(), jQuery data is gone. After .detach(), data survives.

jQuery
$( "#box-a" ).data( "score", 42 );
$( "#box-a" ).remove();
// $.data on #box-a is gone — element discarded

$( "#box-b" ).data( "score", 42 );
var detached = $( "#box-b" ).detach();
console.log( detached.data( "score" ) ); // 42
Try It Yourself

How It Works

jQuery’s internal cache is keyed to DOM nodes. .remove() triggers full cleanup because the nodes are discarded. .detach() skips that cleanup so widgets can be stashed and restored. Choose remove for permanent deletion.

Example 4 — Delete a List Row on Click

Remove the closest list item when the user clicks a delete button.

jQuery
$( "#todo-list" ).on( "click", ".delete-btn", function() {
  $( this ).closest( "li" ).remove();
});
Try It Yourself

How It Works

.closest( "li" ) walks up from the clicked button to the row container, then .remove() deletes that row permanently. Delegated events on the parent list continue to work for remaining items.

Example 5 — Dismiss a Toast Notification

Remove a notification banner from the DOM when the user clicks close.

jQuery
$( ".toast .close" ).on( "click", function() {
  $( this ).closest( ".toast" ).fadeOut( 200, function() {
    $( this ).remove();
  });
});
Try It Yourself

How It Works

Pairing .fadeOut() with .remove() in the animation callback gives a smooth dismiss UX while ensuring the toast is fully removed afterward. Hidden-but-still-in-DOM nodes would accumulate without the final remove call.

🚀 Common Use Cases

  • Todo lists — delete individual rows when the user marks items complete or clicks remove.
  • Toast notifications — dismiss alerts permanently after the user closes them or a timer fires.
  • Modal cleanup — remove overlay and dialog markup after close instead of hiding with CSS.
  • Filtered removal$(".item").remove(".expired") deletes only expired entries.
  • Ajax error states — strip stale error banners before showing a fresh message.
  • Dynamic form fields — remove an added input group when the user clicks “Remove field.”

🧠 How .remove() Deletes DOM Elements

1

Match DOM elements

jQuery collection points at live nodes targeted for deletion.

Select
2

Optional selector filter

If provided, only matching elements in the set are removed.

Filter
3

Clean up jQuery state

Event handlers and .data() on removed nodes are erased.

Cleanup
4

Disconnect from DOM

Elements and all descendants gone from the document — permanent deletion.

📝 Notes

  • Available since jQuery 1.0 — optional selector filter included from the start.
  • Removes matched elements themselves, not just their children (contrast with .empty()).
  • All descendant nodes inside removed elements are deleted as well.
  • jQuery cleans up event handlers and .data() to prevent memory leaks.
  • Use .detach() when you plan to reinsert nodes with events intact.
  • Removed elements cannot be re-queried by selector — they no longer exist in the document.
  • .remove( selector ) is shorthand for .filter( selector ).remove().

Browser Support

.remove() has been part of jQuery since 1.0+. It relies on standard DOM removeChild operations under the hood. Works in all browsers supported by your jQuery build — IE6+ through modern evergreen browsers in legacy jQuery versions, and all current browsers in jQuery 3.x and 4.x.

jQuery 1.0+

jQuery .remove()

Universal DOM deletion API across jQuery 1.x, 2.x, 3.x, and 4.x. No browser-specific polyfills required — jQuery normalizes parent-child removal and internal cleanup. Pair with delegated events for dynamic delete buttons.

100% With jQuery loaded
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() Universal

Bottom line: Default choice for permanent DOM deletion when nodes will not return.

Conclusion

The jQuery .remove() method permanently deletes matched elements from the document along with all descendants. jQuery cleans up associated data and event handlers — exactly as the official demos show when paragraphs are removed with or without a selector filter.

Choose .detach() for temporary removal with state preserved, and .empty() when only inner content should be cleared. Next up: removing parent wrappers with .unwrap().

💡 Best Practices

✅ Do

  • Use .remove() when nodes should be permanently deleted
  • Use the selector argument to filter which elements are removed
  • Pair .fadeOut() with .remove() in the callback for smooth dismiss UX
  • Use delegated events on a parent for dynamic delete buttons
  • Prefer .detach() when widgets may be reinserted later

❌ Don’t

  • Use .remove() when you need to reinsert nodes with events intact
  • Hide elements with CSS instead of removing when they will never return
  • Confuse .remove() with .empty() (self vs children)
  • Expect removed nodes to remain queryable by ID in the document
  • Forget cleanup — jQuery handles it, but detached nodes you stash manually still need management

Key Takeaways

Knowledge Unlocked

Five things to remember about .remove()

The permanent delete API — nodes gone, jQuery cleaned up.

5
Core concepts
# 02

Filter

Selector arg

Target
03

Cleanup

Data gone

Memory
04

vs detach

Preserve

Compare
05

vs empty

Parent stays

Contrast

❓ Frequently Asked Questions

.remove() deletes matched elements from the DOM — the elements themselves and everything inside them are removed from the document. jQuery also cleans up bound event handlers and .data() associated with those nodes. Returns the same jQuery collection. Available since jQuery 1.0.
Both remove elements from the document tree. .remove() permanently discards nodes and cleans up jQuery data and event handlers. .detach() removes nodes from the DOM but preserves jQuery state so you can reinsert them later with .appendTo(). Use remove when nodes will never be needed again.
.remove() deletes the matched elements themselves from the DOM. .empty() keeps the matched parent but removes all child nodes inside it. Use remove to delete a widget; use empty to clear a container shell.
Yes. Pass an optional selector: $("div").remove(".hello") removes only div elements that also match .hello. $("p").remove(":contains('Hello')") removes paragraphs containing that text — equivalent to .filter().remove().
Yes. jQuery removes event handlers bound with .on() and clears the internal data cache for removed elements to prevent memory leaks. If you need handlers to survive removal for later reinsertion, use .detach() instead.
It returns the same jQuery collection that was removed — useful for chaining in rare cases, though the elements are no longer in the document. You cannot re-query removed nodes by selector once they leave the DOM.
Did you know?

jQuery’s .remove() has existed since version 1.0 — one of the original DOM manipulation methods alongside .append() and .empty(). The optional selector filter lets you write $("div").remove(".hello") instead of the longer $("div").filter(".hello").remove(). Under the hood, jQuery walks removed subtrees and unbinds events before disconnecting nodes, which is why .remove() is safer than raw element.parentNode.removeChild(element) when jQuery handlers are involved.

Next: jQuery .unwrap() Method

Remove parent wrappers and leave matched elements in their place in the DOM.

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

6 people found this page helpful