jQuery Callbacks empty() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Callbacks

Definition

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.

Syntax

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

jQuery
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
CallWhat it does
Callbacks objectList to clear
Argumentsempty() takes no parameters
ReturnSame Callbacks object (chainable)

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

Parameters

ParameterDescription
Step 1Register handlers with add() as usual.
Step 2Call empty() to wipe every handler in one step.
Step 3Optionally verify with has(fn) → false.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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.

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.

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.

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: callbacks.has() Method — Check Membership

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

callbacks.has() Method — Check Membership 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.

8 people found this page helpful