jQuery .empty() Method

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

What Is .empty()?

.empty() removes all child nodes (elements and text) from each matched element since jQuery 1.0. The parent stays in the DOM.

Remember
$(".hello").empty()
// <p class="hello">Hello</p>  →  <p class="hello"></p>

$("#list").empty().append("<li>New</li>")  // clear, then rebuild

$("p").remove()   // deletes the <p> itself
$("p").empty()    // keeps <p>, clears inside
NeedUse
Clear a container$(el).empty()
Delete the element$(el).remove()
Park children for later$(el).children().detach()
Replace inner HTML$(el).html(newHtml)

How to Use .empty()

Select the parent, clear its contents, then optionally refill.

  1. Select the container element(s) you want to wipe.
  2. Call .empty() — no arguments.
  3. Children (and nested descendants) are removed; the parent remains.
  4. Chain .append() / .html() if you need new content next.
PieceRequired?Role
Matched setYesParent container(s) to clear
ArgumentsNone.empty() takes no parameters
Return—Same jQuery collection (chainable)

Pseudocode

Pseudocode
for each matched element el:
    for each child (and descendant) of el:
        remove jQuery data and event handlers
        remove child from the DOM
    // el itself stays

return original matched set

// Text nodes count as children — they are removed too

Cheat Sheet

Keep these facts handy while clearing containers.

TopicDetail
Syntax.empty()
SincejQuery 1.0
RemovesAll children + descendants + text
KeepsThe matched parent element
CleanupChild data and handlers cleared
vs removeParent stays vs parent deleted
vs detachDestroy children vs park nodes

Live Preview

Clear a paragraph with .empty(), or reset and refill it.

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

Hello, Person and person.

Result
$("p").empty()
→ parent <p> remains; children gone

jQuery Examples

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

Example 1 — Empty a Paragraph

Remove all content inside every <p>.

jQuery
$("p").empty();
Try It Yourself

How It Works

  1. Select. $("p") matches each paragraph.
  2. Clear. .empty() removes every child node inside.
  3. Text too. Plain text counts as a child — it is deleted.
  4. Parent. The empty <p> tags stay in the document.

Example 2 — .empty() vs .remove()

Clear inside a box, or delete the box entirely.

jQuery
$("#a").empty();   // <div id="a"></div> stays
$("#b").remove();  // #b is gone from the DOM
Try It Yourself

How It Works

  1. empty. Wipes children of #a; the div remains selectable.
  2. remove. Deletes #b from the document tree.
  3. Reuse. Emptied containers can be filled again.
  4. Rule. Keep the shell → empty. Delete the shell → remove.

Example 3 — Empty Then Append

Common pattern: clear a list, then add fresh items.

jQuery
var fruits = ["Apple", "Banana", "Cherry"];
var $list = $("#fruits").empty();
fruits.forEach(function (name) {
  $list.append($("<li>").text(name));
});
Try It Yourself

How It Works

  1. Empty. Old list items are removed safely.
  2. Chain. .empty() returns the same #fruits collection.
  3. Append. New <li> elements are created with .text().
  4. Why. Idempotent redraws without leftover stale nodes.

Example 4 — Nested Descendants Are Cleared

Deep trees inside the parent are removed in one call.

jQuery
$("#panel").empty();
// removes spans, lists, text — everything inside #panel
Try It Yourself

How It Works

  1. Deep clear. Not only direct children — all descendants go.
  2. Cleanup. jQuery strips data/handlers on those nodes first.
  3. Parent. #panel remains an empty container.
  4. Tip. Prefer this over looping .remove() on every child.

Edge Cases & Pitfalls

Check these before wiping a live container.

handlers

Child handlers are destroyed

If you need those nodes again with events intact, .detach() them instead of emptying the parent.

args

No selector argument

.empty() always clears everything inside. To remove a subset, select those children and call .remove().

parent

Parent data stays

.data() and handlers on the matched parent itself are not cleared by .empty() — only descendants are cleaned.

html

.html("") is not clearer intent

Prefer .empty() when you mean “clear children.” Use .html() when you are setting new markup.

Browser Support

.empty() has been part of jQuery since 1.0. It works wherever your loaded jQuery version runs.

✓ Stable · jQuery 1.0+

jQuery .empty()

Supported in all browsers that run jQuery 1.0+. Prefer a current jQuery 3.x build for modern projects.

100% jQuery core method
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
.empty() Universal

Bottom line: Safe for clearing containers before rebuild. Use .detach() when child handlers must survive.

Performance Notes

ApproachCostBest for
.empty()One clear + cleanupWiping a container
Loop .remove() on childrenMore workAvoid — prefer empty
.empty().append(…)Clear + insertList redraws from data

For large lists, empty once, then append a batch (or a fragment). Avoid repeatedly emptying inside a tight animation loop.

Key Takeaways

  • Role: remove all children; keep the parent.
  • Text too: text nodes are children and get cleared.
  • vs remove: empty keeps the shell; remove deletes it.
  • Rebuild: .empty().append(…) for fresh lists.

One line: .empty() wipes a container clean so you can keep the parent and refill it.

Frequently Asked Questions

.empty() removes all child nodes from each matched element — text and nested elements — while the parent stays in the DOM. Returns the same jQuery collection for chaining. Available since jQuery 1.0.
.empty() clears inside the matched element and leaves the parent. .remove() deletes the matched elements themselves. Use empty to wipe a container; use remove to delete the container too.
.empty() destroys children and cleans their jQuery data/handlers. .detach() removes matched elements but keeps data and handlers for later reinsertion. Use empty to clear contents; use detach to stash whole nodes.
Yes. In the DOM, text inside an element is a child node. .empty() removes text as well as element children.
No. To remove only some children, select those descendants and call .remove() or .detach() on them.
Yes. jQuery removes data and handlers from child elements before removing them, which helps avoid memory leaks.
Both can clear contents. .empty() is the dedicated clearer and always cleans child data/handlers. Prefer .empty() when your intent is “clear this container.”

Next: .remove()

Delete matched elements from the document and clean up their data.

.remove() 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.

8 people found this page helpful