jQuery Callbacks empty() Method

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

What Is empty()?

callbacks.empty() removes all callbacks from a list (since jQuery 1.7). The official API: remove all of the callbacks from a list. The list stays reusable — you can add() again. Returns the same Callbacks object for chaining.

Remember
callbacks.add(foo)
callbacks.add(bar)
callbacks.empty()

callbacks.has(foo)  → false
callbacks.has(bar)  → false

callbacks.add(newFn)  // still allowed
callbacks.fire()      // runs newFn only
NeedUse
Clear every handlercbs.empty()
Drop one handlercbs.remove(fn)
Shut down forevercbs.disable()
Check membershipcbs.has(fn)

How to Use empty()

Call it when you want a clean slate but still need the same list object.

  1. Register handlers with add() as usual.
  2. Call empty() to wipe every handler in one step.
  3. Optionally verify with has(fn) → false.
  4. Re-add() new handlers and fire() when ready.
PieceRequired?Role
Callbacks objectYesList to clear
ArgumentsNoneempty() takes no parameters
Return—Same Callbacks object (chainable)

Pseudocode

Pseudocode
list = [fn1, fn2, …]

empty():
  if list is locked:
    ignore
  else:
    list = []          // remove all handlers
  return Callbacks     // still active (unless disabled)

fire(args…):
  for each fn in list:
    call fn(args…)     // no-op when list is []

Cheat Sheet

Keep these facts handy when resetting Callbacks lists.

TopicDetail
Syntaxcallbacks.empty()
ArgumentsNone
EffectRemoves every registered handler
Reusable?Yes — add() / fire() still work
vs remove()All vs specific references
vs disable()Clear vs permanent shutdown
SincejQuery 1.7

Live Preview

Compare clear, reuse, remove, and chain patterns on a fresh list.

Browser demo of callbacks.empty — same ideas as the examples below.

Result
add(foo, bar); empty(); fire()
→ (no output)

jQuery Examples

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

Example 1 — Clear All Callbacks

Add two handlers, call empty(), then fire() — silent.

jQuery
var callbackList = $.Callbacks();

callbackList.add(function () { console.log("Callback 1"); });
callbackList.add(function () { console.log("Callback 2"); });

callbackList.empty();
callbackList.fire(); // no output
Try It Yourself

How It Works

  1. Register. Two handlers join the list.
  2. Empty. Both are removed in one call.
  3. Fire. The queue is empty → nothing prints.
  4. Note. The list object is still alive for future add().

Example 2 — Empty, Then Add Fresh Handlers

The list remains usable — register new callbacks after clearing.

jQuery
var callbacks = $.Callbacks();

callbacks.add(function () { console.log("Old handler"); });
callbacks.empty();

callbacks.add(function () { console.log("New handler"); });
callbacks.fire();
// → New handler
Try It Yourself

How It Works

  1. Old handler. Added, then wiped by empty().
  2. New handler. add() still works on the same list.
  3. Fire. Only the new handler runs.
  4. vs disable. disable() would block this reuse entirely.

Example 3 — empty() vs remove()

remove(fn) drops one handler; empty() clears the rest.

jQuery
var callbacks = $.Callbacks();

function loggerA() { console.log("A"); }
function loggerB() { console.log("B"); }

callbacks.add(loggerA, loggerB);
callbacks.remove(loggerA);
callbacks.fire();
// → B

callbacks.empty();
callbacks.fire(); // no output
Try It Yourself

How It Works

  1. Add both. loggerA and loggerB are registered.
  2. Remove one. Only A is dropped → fire prints B.
  3. Empty. The remaining handler is cleared.
  4. Rule. Surgical unsubscribe → remove; full reset → empty.

Example 4 — Reset an Event Bus Between Steps

Clear subscribers when moving to a new wizard step or route.

jQuery
var StepBus = (function () {
  var onEnter = $.Callbacks();

  return {
    onEnter: onEnter,
    enterStep: function (name) {
      onEnter.fire(name);
    },
    reset: function () {
      onEnter.empty();
      console.log("Bus reset for next step");
    }
  };
})();

StepBus.onEnter.add(function (s) { console.log("Enter:", s); });
StepBus.enterStep("billing");  // → Enter: billing
StepBus.reset();
StepBus.enterStep("review");   // no output — no handlers
Try It Yourself

How It Works

  1. Subscribe. Step-one handlers attach to onEnter.
  2. Enter billing. Handlers run for that step.
  3. Reset. empty() drops stale listeners.
  4. Next step. Fire finds no handlers until you re-subscribe.

Example 5 — Chain empty().add().fire()

empty() returns the list, so you can replace handlers in one fluent chain.

jQuery
var callbacks = $.Callbacks();

callbacks
  .add(function () { console.log("v1"); })
  .fire(); // → v1

callbacks
  .empty()
  .add(function () { console.log("v2"); })
  .fire(); // → v2
Try It Yourself

How It Works

  1. First chain. Add v1 and fire → v1.
  2. Empty. Clears v1; returns the same object.
  3. Add v2 and fire. Only the new handler runs.
  4. Fluent API. Same pattern as other chainable Callbacks methods.

Edge Cases & Pitfalls

Check these before using empty() as a reset.

alive

List stays active

empty() is not disable(). New add() / fire() calls still work.

lock

Locked lists ignore empty()

After lock(), membership is frozen — empty() / add() / remove() do not change the list.

disable

Empty does not undo disable

If disable() already ran, clearing handlers does not re-enable firing.

memory

Flags stay the same

empty() does not change once / memory / unique behavior set at creation.

verify

Confirm with has()

After empty(), has(fn) returns false for previously registered references — the official check.

Browser Support

callbacks.empty() is part of jQuery’s Callbacks API (since 1.7). It works in any browser where your jQuery build runs — the list logic lives in jQuery, not as a separate browser API.

✓ jQuery 1.7+ · Browsers

jQuery callbacks.empty()

Supported in jQuery 1.x, 2.x, and 3.x across Chrome, Firefox, Safari, Edge, and other browsers with jQuery loaded.

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
callbacks.empty() Browsers

Bottom line: Safe wherever jQuery is loaded. Use empty() to reset handlers; use disable() when the list must never fire again.

Performance Notes

OperationCostBest for
empty()O(1) clear*Full reset without naming handlers
remove(fn)O(n) scanDropping one known reference
Many removesO(n × k)Prefer one empty() instead

*Implementation details vary, but clearing the whole list is cheaper than removing handlers one by one when you want none left. Reuse the same Callbacks object after empty() instead of allocating a new one every time — unless you also need different flags.

Key Takeaways

  • Role: wipe every handler in one call.
  • Reusable: the list stays active for new add() / fire().
  • vs remove: all handlers vs one reference.
  • Verify: has(fn) returns false after a successful clear.

One line: empty() resets the queue without killing the bus.

Frequently Asked Questions

empty() removes every handler from the Callbacks list in one call. After empty(), fire() runs nothing until you add() new functions. The list itself stays active — unlike disable(), which permanently shuts down firing.
remove(fn) drops specific function references you pass in. empty() wipes the entire list at once — useful when you want a clean slate without tracking each handler.
empty() clears handlers but the list can still accept add() and fire() afterward. disable() permanently prevents all future firing; disabled() stays true.
Yes. It returns the same Callbacks object, so you can chain: callbacks.empty().add(fn).fire().
Use has(fn) for a known reference — after empty(), has(foo) returns false for every previously registered function. That matches the official API example.
On a locked list, empty() is ignored (membership is frozen). On a disabled list, clearing handlers does not re-enable firing — disabled() stays true. Prefer empty() on active lists you plan to reuse.

Next: has()

Check whether a Callbacks list has any handlers or a specific one.

has() 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