jQuery Callbacks has() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Membership check

What You’ll Learn

The has() method checks whether a specific function reference is already registered on a Callbacks list. This tutorial covers syntax, five examples, how it compares with add() and remove(), and patterns for avoiding duplicate subscriptions.

01

Syntax

has(callback)

02

Boolean

true / false

03

Reference

Same function object

04

vs add()

Check before add

05

vs fired()

Different question

06

Dedup

Skip duplicates

Introduction

You use add() to register handlers and fire() to run them. But what if the same handler gets added twice by mistake — or you need to know whether a subscriber is already on the list before calling remove()?

has() answers that membership question. Pass the function reference you care about; jQuery returns true if that exact function is currently stored in the list.

Understanding the has() Method

callbacks.has(callback) performs a lookup by reference equality. It returns true only when the same function object you pass was previously added with add() and has not been removed with remove() or cleared with empty().

It does not accept flags, does not tell you whether the list is empty, and does not track whether fire() has run. The old reference incorrectly documented has(flags) and has() with no arguments — neither matches jQuery’s actual API.

💡
Beginner Tip

Store your handler in a named variable first. has() needs that same variable reference — not a freshly created anonymous function with identical code.

📝 Syntax

General form of callbacks.has:

jQuery
callbacks.has( callback )

Parameters

  • callback — The function reference to look up in the list.

Return value

  • true if the callback is registered; false otherwise.

Basic pattern

jQuery
const callbacks = $.Callbacks();



function onReady() {

  console.log("Ready!");

}



callbacks.add(onReady);

console.log(callbacks.has(onReady)); // true



function otherHandler() {}

console.log(callbacks.has(otherHandler)); // false

⚡ Quick Reference

GoalCode
Check if handler is registeredcallbacks.has(fn)
Add only if missingif (!callbacks.has(fn)) callbacks.add(fn)
After remove()has(fn)false
Register handlercallbacks.add(fn)
List ever fired?callbacks.fired()

📋 has() vs add() vs fired()

Membership check versus registration versus invocation status.

has(fn)
boolean

Is this function on the list?

add(fn)
register

Put a handler on the list

fired()
boolean

Has fire() ever run?

Side effect
none

has() is read-only

Examples Gallery

Each example shows a different way to use the boolean from has().

📚 Getting Started

Check membership for a known function reference.

Example 1 — Registered vs Unregistered Handler

Add one handler, then test has() with that reference and a different function.

jQuery
const callbacks = $.Callbacks();



function onReady() {

  console.log("Ready!");

}



function onError() {}



callbacks.add(onReady);



console.log("has(onReady):", callbacks.has(onReady)); // true

console.log("has(onError):", callbacks.has(onError)); // false
Try It Yourself

How It Works

has() matches the exact function object you pass — not functions that merely look similar.

Example 2 — Before and After add()

Membership is false on an empty list, then true once the handler is added.

jQuery
const callbacks = $.Callbacks();

const handler = function () { console.log("Handler ran"); };



console.log("Before add:", callbacks.has(handler)); // false



callbacks.add(handler);

console.log("After add:", callbacks.has(handler));  // true



callbacks.fire(); // Handler ran
Try It Yourself

How It Works

Calling fire() does not change has() — the handler stays registered until you remove() or empty() it.

📈 Practical Patterns

Dedup guards, removal checks, and reference pitfalls.

Example 3 — Prevent Duplicate Subscriptions

Only add() when has() returns false.

jQuery
const callbacks = $.Callbacks();

const handler = function () { console.log("Subscribed"); };



function subscribe(fn) {

  if (!callbacks.has(fn)) {

    callbacks.add(fn);

    console.log("Added handler");

  } else {

    console.log("Already subscribed — skipped");

  }

}



subscribe(handler);

subscribe(handler); // duplicate attempt
Try It Yourself

How It Works

Callbacks does not deduplicate automatically. A has() guard is a simple way to avoid running the same handler twice on every fire().

Example 4 — After remove()

Membership flips back to false once the handler is removed.

jQuery
const callbacks = $.Callbacks();

const handler = function () { console.log("Tick"); };



callbacks.add(handler);

console.log("After add:", callbacks.has(handler));    // true



callbacks.remove(handler);

console.log("After remove:", callbacks.has(handler)); // false
Try It Yourself

How It Works

empty() would also make has(handler) return false for every handler that was cleared.

Example 5 — Reference Equality Matters

Two functions with identical bodies are not the same reference.

jQuery
const callbacks = $.Callbacks();



const stored = function () { console.log("A"); };

callbacks.add(stored);



const lookalike = function () { console.log("A"); };



console.log("has(stored):", callbacks.has(stored));       // true

console.log("has(lookalike):", callbacks.has(lookalike));   // false
Try It Yourself

How It Works

Always keep a stable reference to handlers you may need to check, remove, or deduplicate later.

🚀 Use Cases

  • Duplicate prevention — guard add() when the same handler might register twice.
  • Safe unsubscribe — verify membership before calling remove().
  • Plugin APIs — expose isSubscribed(fn) backed by has(fn).
  • Unit tests — assert a mock handler was registered on a Callbacks list.
  • Conditional wiring — attach optional listeners only when not already present.

🧠 How has() Looks Up Handlers

1

Pass callback

Supply the function reference you want to find.

Input
2

List scan

jQuery compares by reference against registered handlers.

Lookup
3

Return boolean

true if found; false if not. No list mutation.

Result
=

Confident membership

You know whether a specific handler is on the list before you act.

📝 Notes

  • has() requires a callback argument — it does not accept flags.
  • Matching is by reference, not by function source code or name.
  • Adding the same reference twice makes has() true, but fire() will run it twice.
  • has() is unrelated to fired() (invocation history) and disabled() (shutdown status).
  • After empty(), every previous handler returns false from has().

Browser Support

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

jQuery 1.7+

jQuery Callbacks.has()

Supported in jQuery 1.x, 2.x, and 3.x. Reference lookup behaves consistently across browsers.

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

Bottom line: Safe in jQuery projects. Pass the exact function reference you added with add().

🎉 Conclusion

The callbacks.has() method tells you whether a specific function reference is registered on a Callbacks list. It is read-only, returns a boolean, and pairs naturally with add() and remove() for membership-aware code.

Next, learn lock() to freeze the list so no new handlers can be added — while still allowing fire().

💡 Best Practices

✅ Do

  • Store handlers in named variables for has() lookups
  • Guard add() with if (!has(fn))
  • Use has() before remove() when unsure
  • Expose membership checks in plugin subscribe APIs
  • Test registration with has(mockFn)

❌ Don’t

  • Pass flags to has() — unsupported
  • Call has() with no argument expecting “list empty”
  • Confuse has() with fired()
  • Expect lookalike functions to match by code
  • Rely on has() after losing the original reference

Key Takeaways

Knowledge Unlocked

Five things to remember about has()

Membership checks for Callbacks lists.

5
Core concepts
T/F 02

Boolean

Registered?

Return
🔗 03

Reference

Same object

Match
+ 04

add()

Register fn

Pair
05

fired()

Different check

Compare

❓ Frequently Asked Questions

has(callback) checks whether a specific function reference is currently registered on the Callbacks list. It returns true if that exact function was added and not yet removed, otherwise false.
No. Unlike incorrect documentation sometimes found online, has() takes a callback function — not flags. Flags belong on $.Callbacks("once memory") at creation time.
has(fn) asks "is this function on the list?" fired() asks "has the list been invoked at least once?" They answer completely different questions.
Only if you keep a reference to the same function object. has() uses reference equality — two separately declared functions with identical code are not considered the same.
No meaningful membership check occurs without passing the function you want to look up. Always pass the callback reference: callbacks.has(myHandler).
Common uses: prevent duplicate add() of the same handler, guard remove() when unsure of membership, and write tests that assert a subscriber was registered.
Did you know?

jQuery Callbacks does not prevent duplicate registrations. If you call add(sameFn) twice, has(sameFn) is true — but the next fire() invokes that function twice. A has() guard before add() is the standard fix.

Continue to lock()

Learn how to lock a Callbacks list so no new handlers can be added.

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