jQuery callbacks.has() Method — Check Membership

Beginner
5 min read
Updated: Nov 2026
3 examples
Callbacks

Definition

callbacks.has([callback]) returns a boolean (since jQuery 1.7). With a function, it asks whether that handler is on the list. With no argument, it asks whether the list has any callbacks attached.

Syntax

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

jQuery
callbacks.has(foo)   // true if foo is on the list
callbacks.has(bar)   // false if bar was never added
callbacks.has()      // true if the list is non-empty
CallWhat it does
callbackFunction to look up; omit = “any attached?”
Returntrue / false (boolean)

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

Parameters

ParameterDescription
Step 1Store handlers in named variables (not only inline anonymous functions).
Step 2add() the ones you need.
Step 3Call has(fn) for one handler, or has() for “any left?”.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.

jQuery Examples

Example 1 — Specific Function on the List

Official style: has(foo) vs has(bar).

jQuery
var foo = function (value1, value2) {
  console.log("Received: " + value1 + "," + value2);
};
var bar = function (value1, value2) {
  console.log("foobar");
};

var callbacks = $.Callbacks();
callbacks.add(foo);

console.log(callbacks.has(foo));  // true
console.log(callbacks.has(bar));  // false
Try It Yourself

How It Works

  1. Define two named functions, foo and bar.
  2. Add only foo to the list.
  3. has(foo) finds that same object → true.

Example 2 — Any Callbacks Attached?

Omit the argument to ask if the list is non-empty.

jQuery
var cbs = $.Callbacks();
console.log(cbs.has());  // false

cbs.add(function () { /* ... */ });
console.log(cbs.has());  // true

cbs.empty();
console.log(cbs.has());  // false
Try It Yourself

How It Works

  1. Fresh list. has() is false.
  2. After add. At least one handler → true.
  3. After empty. List cleared → false again.

Example 3 — has() After remove()

Membership flips when you unregister the same reference.

jQuery
var onReady = function () {
  console.log("ready");
};

var cbs = $.Callbacks();
cbs.add(onReady);
console.log(cbs.has(onReady));  // true

cbs.remove(onReady);
console.log(cbs.has(onReady));  // false
Try It Yourself

How It Works

  1. Add onReady — it is on the list.
  2. has returns true.
  3. remove the same reference.

Frequently Asked Questions

has() returns a boolean. With no argument, it tells you whether the list currently has any callbacks. With a function argument, it tells you whether that exact function is on the list.
has() checks membership (handlers on the list). fired() checks whether fire() or fireWith() has run at least once. A list can have handlers and never be fired, or be fired and later emptied.
Yes. Pass the same function object you added. Two separately written functions with identical code are not the same — has() will return false for the second one.
Yes. Officially, omitting the callback asks whether the list has any callbacks attached (non-empty). Use has(fn) when you care about one specific handler.
No. It is a read-only check. Use add(), remove(), empty(), or fire() to change or invoke the list.
Guard duplicate add() when you cannot use the unique flag, confirm a handler before remove(), or assert in tests that a subscriber was registered.

Next: callbacks.fire() Method — Invoke Handlers

Invoke every handler currently on the Callbacks list.

callbacks.fire() Method — Invoke Handlers 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