jQuery Callbacks empty() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Clear handlers

What You’ll Learn

The empty() method removes every handler from a jQuery Callbacks list in one step. The list stays active — you can add() and fire() again afterward. This tutorial covers syntax, five examples, and how empty() differs from remove() and disable().

01

Syntax

callbacks.empty()

02

Clear all

Every handler

03

Re-use

List stays live

04

vs remove()

One vs many

05

vs disable()

Clear vs kill

06

Reset

Event buses

Introduction

Callback lists grow as features subscribe to events — click handlers, AJAX hooks, plugin extensions. Over time you may need to wipe every subscriber without destroying the list itself. That is what empty() does: one call, zero handlers left.

Unlike disable(), which permanently turns firing off, empty() only clears the queue. You can register fresh handlers and continue using the same Callbacks object — ideal for resettable event buses and multi-step workflows.

Understanding the empty() Method

callbacks.empty() takes no arguments and removes all functions currently stored in the list. It also clears internal firing memory associated with those handlers, so the next fire() starts from a clean slate.

After empty(), calling fire() does nothing until you add() at least one new handler. The list is not disabled — disabled() remains false unless you previously called disable().

💡
Beginner Tip

Use empty() when you want to reset subscribers. Use disable() when the list should never fire again — such as after plugin destroy.

📝 Syntax

General form of callbacks.empty:

jQuery
callbacks.empty()

Parameters

  • None.

Return value

  • Returns the same Callbacks object for method chaining.

Basic pattern

jQuery
const callbackList = $.Callbacks();



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

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



callbackList.empty();



callbackList.fire(); // no output — list is empty

⚡ Quick Reference

GoalCode
Remove all handlerscallbacks.empty()
Remove specific handlerscallbacks.remove(fn)
Shut down list permanentlycallbacks.disable()
Clear then re-subscribecallbacks.empty().add(fn)
Fire after empty (no handlers)callbacks.fire() → no-op

📋 empty() vs remove() / disable()

Pick the method that matches how much of the list you want to change.

empty()
clear all

List stays active; add/fire again

remove()
drop fn

Remove one or more specific handlers

disable()
kill list

Permanent shutdown — no more firing

After empty
disabled: false

Unless disable() was called earlier

Examples Gallery

Each example demonstrates clearing handlers and what happens on the next fire().

📚 Getting Started

Remove every handler, then fire — nothing runs.

Example 1 — Clear All Callbacks

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

jQuery
const 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

empty() drops both handlers. fire() still runs but finds an empty queue.

Example 2 — Empty, Then Add Fresh Handlers

The list remains usable — register new callbacks after clearing.

jQuery
const 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

This is the key difference from disable(): after empty(), the bus is blank but still alive for new subscribers.

📈 Practical Patterns

Targeted removal, resets, and chaining.

Example 3 — empty() vs remove()

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

jQuery
const 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

Use remove() for surgical unsubscription. Use empty() when you want zero handlers left without naming each one.

Example 4 — Reset an Event Bus Between Steps

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

jQuery
const StepBus = (function () {

  const 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

Prevents stale handlers from step one firing during step two. Re-register listeners after each reset if needed.

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

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

jQuery
const 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

Swapping handler sets is common in versioned plugin APIs — clear old, attach new, fire immediately.

🚀 Use Cases

  • Event handler reset — clear all listeners before rebinding on DOM refresh.
  • Wizard / multi-step UI — drop step-specific hooks when advancing.
  • Test isolation — empty shared Callbacks fixtures between test cases.
  • Memory hygiene — release handler references on long-lived SPAs without destroying the bus object.
  • Handler replacement — swap entire callback sets via empty().add(...).

🧠 How empty() Works

1

Handlers queued

add() builds a list of functions waiting for fire().

Subscribe
2

empty()

All handlers and firing memory are discarded; list object stays active.

Clear
3

Re-populate

Optional: add() new handlers and fire() again.

Reuse
=

Clean slate

Same bus object, zero stale subscribers.

📝 Notes

  • empty() does not call disable() — the list can still fire after new add() calls.
  • On a list already disable()d, empty() does not re-enable firing.
  • If the list is lock()ed, mutating methods including empty() may be restricted — see the lock() tutorial.
  • Prefer remove(fn) when only one subscriber leaves.
  • After empty(), has(fn) returns false for all previous handlers.

Browser Support

callbacks.empty() is part of jQuery’s Callbacks API since jQuery 1.7 and works wherever jQuery runs.

jQuery 1.7+

jQuery Callbacks.empty()

Supported in jQuery 1.x, 2.x, and 3.x across all browsers with a compatible jQuery build.

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

Bottom line: Safe in jQuery projects. Use empty() for reset; use disable() for permanent shutdown.

🎉 Conclusion

The callbacks.empty() method clears every handler from a Callbacks list while keeping the list itself active. It is the right tool for resets, step changes, and handler replacement — not for permanent teardown (use disable()).

Next, learn fire() — the method that invokes whatever handlers remain in the list.

💡 Best Practices

✅ Do

  • Use empty() for full list resets
  • Re-add handlers after reset when still needed
  • Document when shared buses get cleared
  • Chain empty().add(fn) for handler swaps
  • Prefer disable() for destroy, not empty()

❌ Don’t

  • Confuse empty() with disable()
  • Expect old handlers to run after empty()
  • Call empty() on locked lists without checking
  • Clear shared buses other modules still rely on
  • Use empty() when remove() suffices

Key Takeaways

Knowledge Unlocked

Five things to remember about empty()

Clear every handler, keep the list alive.

5
Core concepts
02

Re-use

add/fire OK

Reset
03

remove()

One handler

Compare
🚫 04

disable()

Permanent

Contrast
05

fire()

Next step

Invoke

❓ 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 and clears internal state; disabled() stays true.
Yes. It returns the same Callbacks object, so you can chain: callbacks.empty().add(fn).fire().
Yes, but it is a no-op when no handlers remain. Add new callbacks first if you expect output.
empty() clears handlers, but if disable() was already called, the list remains disabled — disabled() stays true and fire() still does nothing. Use empty() on active lists you plan to reuse.
Did you know?

Calling empty() on a list with the memory flag clears stored fire arguments too — late add() callbacks will not replay old values until you fire() again.

Continue to fire()

Learn how to execute every handler remaining in a Callbacks list.

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