jQuery Callbacks locked() Method

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

What You’ll Learn

The locked() method asks whether a Callbacks list has been frozen with lock(). It returns a boolean and changes nothing. This tutorial covers syntax, five examples, and how it pairs with lock(), disabled(), and safe registration patterns.

01

Syntax

callbacks.locked()

02

Boolean

true / false

03

Read-only

No side effects

04

vs lock()

Check vs action

05

vs disabled()

Different state

06

fire()

Still works

Introduction

After you call lock(), the handler list is frozen — add(), remove(), and empty() silently do nothing. But other code may need to know whether that freeze already happened. Should we try to register a late handler? Is init complete?

locked() answers those questions. It is the status companion to lock(), just as disabled() complements disable() and fired() complements fire().

Understanding the locked() Method

callbacks.locked() returns true once lock() has been called on that list. On a brand-new list that has never been locked, it returns false.

It does not lock the list, return a new Callbacks object, or limit how many handlers run on fire(). The old reference incorrectly showed var lockedCallbacks = myCallbacks.locked() and described concurrency control — that is not how jQuery works.

💡
Beginner Tip

Memory trick: lock() does it; locked() asks “is it frozen?” — same pattern as fire() / fired() and disable() / disabled().

📝 Syntax

General form of callbacks.locked:

jQuery
callbacks.locked()

Parameters

  • None.

Return value

  • true if the list has been locked; false otherwise.

Basic pattern

jQuery
const callbacks = $.Callbacks();



console.log(callbacks.locked()); // false



callbacks.lock();

console.log(callbacks.locked()); // true

⚡ Quick Reference

GoalCode
Check if list is frozenif (callbacks.locked()) { ... }
Freeze the listcallbacks.lock()
Never locked yetlocked()false
After lock()locked()true
List shut down?callbacks.disabled()

📋 lock() vs locked()

Action method versus read-only freeze status.

lock()
action

Freezes add/remove/empty

locked()
boolean

Has lock() been called?

Side effect
yes / no

lock yes; locked no

fire()
still runs

When locked() is true

Examples Gallery

Each example shows a different use of the boolean from locked().

📚 Getting Started

Status flips from false to true after lock().

Example 1 — Before and After lock()

Query status on a fresh list, lock it, then query again.

jQuery
const callbacks = $.Callbacks();



console.log("Before lock:", callbacks.locked()); // false



callbacks.add(function () { console.log("Handler ran"); });

callbacks.lock();

console.log("After lock:", callbacks.locked());  // true
Try It Yourself

How It Works

Even if you lock an empty list, locked() becomes true — the list was frozen, regardless of handler count.

Example 2 — Fresh List Returns false

A newly created Callbacks object is never locked until you call lock().

jQuery
const callbacks = $.Callbacks();



callbacks.add(function () { console.log("Active"); });



console.log("locked():", callbacks.locked()); // false

console.log("Can still add:", !callbacks.locked());
Try It Yourself

How It Works

Default lists accept add() and remove() until lock() runs.

📈 Practical Patterns

Registration guards, firing on locked lists, and status comparisons.

Example 3 — Guard add() When Locked

Log a clear message instead of silently failing when registration is closed.

jQuery
const hooks = $.Callbacks();



function subscribe(fn) {

  if (hooks.locked()) {

    console.log("Registration closed — cannot add handler");

    return;

  }

  hooks.add(fn);

}



hooks.lock();

subscribe(function () { console.log("Late handler"); });
Try It Yourself

How It Works

jQuery’s add() after lock fails silently. Checking locked() first gives users and developers a helpful signal.

Example 4 — fire() When locked() Is True

Locking does not block invocation — handlers still run.

jQuery
const callbacks = $.Callbacks();



callbacks.add(function () { console.log("Handler fired"); });

callbacks.lock();



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

callbacks.fire(); // → Handler fired
Try It Yourself

How It Works

locked() tracks freeze status, not whether firing is allowed. That distinction matters when comparing with disabled().

Example 5 — locked() vs disabled()

These status methods answer different questions about the same list.

jQuery
const locked = $.Callbacks();

locked.lock();

console.log("locked:", locked.locked());     // true

console.log("disabled:", locked.disabled()); // false



const disabled = $.Callbacks();

disabled.disable();

console.log("locked:", disabled.locked());     // false

console.log("disabled:", disabled.disabled()); // true
Try It Yourself

How It Works

A list can be locked but still active for firing, or disabled without ever being locked. Check the status that matches your question.

🚀 Use Cases

  • Registration guards — warn when add() is attempted after init closed.
  • Plugin APIs — expose isLocked() backed by locked().
  • Unit tests — assert lock() ran after setup phase.
  • Debugging — explain why late add() had no effect.
  • Lifecycle checks — branch logic when init locked hooks but events should still fire.

🧠 How locked() Fits the Lifecycle

1

New list

locked() is false — open for add/remove.

Open
2

lock()

List frozen; internal locked flag set to true.

Freeze
3

locked()

Status query returns true; no state change.

Query
=

Informed registration

Code knows whether the handler set is still mutable.

📝 Notes

  • locked() takes no parameters and returns a boolean only.
  • It does not return a Callbacks object — that was a documentation error in older material.
  • After lock(), locked() stays true permanently — no unlock() exists.
  • Do not confuse with disabled(), which tracks disable() instead.
  • fire() works when locked() is true; it does not when disabled() is true.

Browser Support

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

jQuery 1.7+

jQuery Callbacks.locked()

Supported in jQuery 1.x, 2.x, and 3.x. Returns a boolean 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.locked() Universal

Bottom line: Safe in jQuery projects. Use lock() to freeze; use locked() to check freeze status.

🎉 Conclusion

The callbacks.locked() method tells you whether a Callbacks list has been frozen with lock(). It is read-only, takes no arguments, and pairs naturally with lock() and the distinction from disabled().

Next, learn remove() to unregister specific handlers from an unlocked list.

💡 Best Practices

✅ Do

  • Use locked() before attempting late add()
  • Pair with lock() at end of init phase
  • Expose isLocked() wrapping locked() in plugins
  • Assert locked() in tests after lock()
  • Distinguish from disabled() in docs and logs

❌ Don’t

  • Expect locked() to return a Callbacks object
  • Confuse it with concurrency / mutex locking
  • Expect locked() to block fire()
  • Look for an unlock() method
  • Call lock() when you only meant to check status

Key Takeaways

Knowledge Unlocked

Five things to remember about locked()

Freeze status for Callbacks lists.

5
Core concepts
T/F 02

Boolean

Ever locked?

Return
🔒 03

lock()

Sets true

Action
04

fire()

Still runs

Invoke
🚫 05

disabled()

Different check

Compare

❓ Frequently Asked Questions

locked() is a read-only status check. It returns true if lock() was called on the list, otherwise false. It does not lock anything itself — use lock() for the action.
lock() is the verb — it freezes the list so add(), remove(), and empty() stop working. locked() is the question — "is this list frozen?" It returns a boolean and changes nothing.
No. Unlike incorrect examples sometimes found online, locked() returns a boolean (true/false), not a separate callback list you can fire.
locked() tracks whether lock() was called. disabled() tracks whether disable() was called. A list can be locked but still fire handlers; a disabled list cannot fire at all.
After lock() runs on that Callbacks object. It stays true permanently — jQuery provides no unlock() method.
Common uses: skip add() when registration is closed, assert init completed before tests fire handlers, debug why late subscribers silently fail, and expose isLocked() in plugin APIs.
Did you know?

jQuery names Callbacks status methods consistently: lock() / locked(), disable() / disabled(), and fire() / fired() — verb for the action, past-participle-style name for the boolean check.

Continue to remove()

Learn how to unregister specific handlers from a Callbacks list.

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