The .clearQueue() instance method removes every function on a jQuery queue that has not yet run. This tutorial covers syntax, the default fx effects queue, comparisons with .stop() and .dequeue(), the official Start/Stop demo, named custom queues, rapid-click guards, and five hands-on examples.
01
Syntax
.clearQueue(name)
02
fx queue
Default effects
03
Pending only
Not yet run
04
Chainable
Returns jQuery
05
vs stop(true)
Similar on fx
06
Custom queues
Any queue name
Fundamentals
Introduction
jQuery chains animations and callbacks on a per-element queue. When you call .show(), .animate(), or .queue(fn), steps land on the default fx effects queue and run one at a time. Leftover items can still fire if the user interrupts the chain.
.clearQueue(), added in jQuery 1.4, empties that waiting list — every function that has not started yet. It returns the same jQuery collection for chaining. On fx it behaves like .stop(true), but unlike .stop() it also clears non-animation functions added via .queue().
Concept
Understanding the .clearQueue() Method
.clearQueue( [queueName] ) is an instance method on jQuery collections. It accepts an optional String queue name (default "fx") and returns a jQuery object.
It does not undo effects in progress — only pending entries. Pair with .stop() to halt the current animation, as the official jQuery API demo does on Stop.
💡
Beginner Tip
Think of the queue as a to-do list. .clearQueue() crosses off every task not yet started. .stop() interrupts the task happening right now.
Foundation
📝 Syntax
General form of .clearQueue:
jQuery
jQuery( selector ).clearQueue( [queueName] )
Parameters
queueName (optional String) — name of the queue to clear. Defaults to "fx", the standard effects queue.
Return value
A jQuery object — the same collection, so you can chain further methods.
Official jQuery API description
jQuery
// Remove all pending fx queue items
myDiv.clearQueue();
// Remove pending items from a custom queue
myDiv.clearQueue( "tasks" );
// Official Stop handler — clear waiting + halt current effect
myDiv.clearQueue();
myDiv.stop();
Cheat Sheet
⚡ Quick Reference
Goal
Code
Clear default effects queue
$el.clearQueue()
Clear a named custom queue
$el.clearQueue("tasks")
Cancel pending + stop current
$el.clearQueue().stop()
Inspect queue before clearing
$el.queue("fx").length
Rapid-click guard
$el.clearQueue().animate(...)
Animation-only clear (similar)
$el.stop(true)
Compare
📋 .clearQueue vs .stop(true) vs .stop() vs .dequeue vs .queue
Five queue-related methods — each plays a different role in jQuery’s animation pipeline.
clearQueue
drop pending
Removes all not-yet-run items; fx or custom queues
stop(true)
fx pending
Clears fx queue; animation-focused; optional jumpToEnd
stop()
halt now
Stops current effect; pending items remain unless clearQueue
dequeue
run next
Executes the next queued function — advances the queue
queue
add / read
Push a function or return the current queue array
Hands-On
Examples Gallery
Each example demonstrates .clearQueue() on real animation chains. Open DevTools or use the Try-it links. Example 1 mirrors the official jQuery API Start/Stop demo.
📚 Getting Started
Official animation chain and Stop handler from the jQuery API.
Example 1 — Official Start/Stop Demo
Start chains .show(), .animate(), queued class toggles, and .slideUp(). Stop calls clearQueue() then stop() to drop pending steps and halt the current effect.
jQuery
$( "#start" ).on( "click", function() {
var myDiv = $( "div" );
myDiv.show( "slow" );
myDiv.animate({ left: "+=200" }, 5000 );
myDiv.queue(function() {
var that = $( this );
that.addClass( "newcolor" );
that.dequeue();
});
myDiv.animate({ left: "-=200" }, 1500 );
myDiv.queue(function() {
var that = $( this );
that.removeClass( "newcolor" );
that.dequeue();
});
myDiv.slideUp();
});
$( "#stop" ).on( "click", function() {
var myDiv = $( "div" );
myDiv.clearQueue();
myDiv.stop();
});
Start: div animates through the full chain
Stop: pending animate/slideUp steps removed; current effect halted
How It Works
Each chained method adds steps to the fx queue. .clearQueue() removes everything waiting — including the queued callbacks and .slideUp(). .stop() stops the animation currently running so the div does not keep moving.
📈 Practical Patterns
Compare with stop, custom queues, click guards, and queue inspection.
Example 2 — .clearQueue() vs .stop(true)
A custom function queued with .queue() is removed by .clearQueue() but not by .stop(true) alone — illustrating why clearQueue is the queue-generic tool.
jQuery
var $box = $( "#box" );
$box.animate({ width: 200 }, 2000 );
$box.queue(function( next ) {
console.log( "custom callback queued" );
next();
});
// stop(true) clears fx animation steps but may leave custom queue fns
$box.stop( true );
console.log( "after stop(true):", $box.queue( "fx" ).length );
// clearQueue removes ALL pending fx items including custom fns
$box.clearQueue();
console.log( "after clearQueue:", $box.queue( "fx" ).length );
after stop(true): 0 or 1 (depends on timing)
after clearQueue: 0
How It Works
On pure animation chains, .stop(true) and .clearQueue() look alike. Once you .queue() arbitrary callbacks onto fx, only .clearQueue() guarantees every pending function is removed regardless of type.
Example 3 — Clear a Named Custom Queue
Queues are not limited to fx. Pass a queue name to target serial tasks added with .queue("tasks", fn).
Each click: queue cleared, current toggle stopped, fresh animate starts
No stacked height toggles from fast clicking
How It Works
Without clearing, each click appends another .animate() to fx, causing stuttery open/close sequences. .clearQueue().stop() resets the pipeline before enqueueing the next toggle.
Example 5 — Inspect Queue Length Before and After
Use .queue("fx") to read the pending array, then confirm .clearQueue() reduced it to zero.
pending count: 2 (fadeOut + possibly more depending on timing)
after clearQueue: 0
How It Works
.queue() without a function argument returns the array of pending callbacks. The currently running effect is not counted as pending — only steps waiting their turn. After .clearQueue(), the array is empty.
Applications
🚀 Common Use Cases
Cancel animation chains — drop pending .animate() steps when the user navigates away.
Stop buttons — pair .clearQueue() with .stop() like the official jQuery demo.
Rapid interaction guards — clear fx before starting a fresh toggle or slide.
Custom serial tasks — abort a named tasks queue without touching effects.
Modal / overlay cleanup — prevent queued fade-outs from firing after manual close.
Plugin teardown — empty element queues before removing DOM nodes or re-initing widgets.
🧠 How .clearQueue() Empties a Queue
1
Chain methods
.animate(), .queue(fn), etc. push functions onto the queue.
Enqueue
2
jQuery runs current step
One function executes; remaining items wait in the array.
Active
3
Call .clearQueue()
Pending array is truncated — not-yet-run functions are discarded.
Clear
4
⏹
Return jQuery
Chain .stop() or start new animations on a clean queue.
Important
📝 Notes
Available since jQuery 1.4; returns the jQuery collection (chainable).
Default queue name is "fx" — the standard effects queue.
Similar to .stop(true) on fx, but also removes non-animation .queue() callbacks.
Does not stop the currently running effect — use .stop() for that.
Named queues ("tasks", etc.) are cleared independently of fx.
Inspect pending work with .queue(name) before deciding to clear.
Compatibility
Browser Support
.clearQueue() is a jQuery instance method since 1.4+. It relies on jQuery’s internal queue system, not on browser-specific APIs — behavior is consistent wherever jQuery runs.
✓ Stable · jQuery 1.4+
jQuery .clearQueue()
Supported in all jQuery 1.x, 2.x, 3.x, and 4.x releases. Works in Chrome, Firefox, Safari, Edge, IE 6+ (with compatible jQuery builds), and Node.js via jsdom.
100%jQuery queue API support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.clearQueue()Universal
Bottom line: Learn .clearQueue() alongside .stop() and .queue() to manage animation pipelines confidently in legacy and modern jQuery apps.
Wrap Up
Conclusion
The .clearQueue() method removes every function on a jQuery queue that has not yet executed. On fx it behaves like .stop(true) for pending animations, but also clears arbitrary .queue() callbacks.
For user-initiated cancellation, combine .clearQueue() with .stop() — as the official demo recommends — so both waiting and in-progress effects are handled.
Call .clearQueue() before starting fresh animations on rapid clicks
Pair with .stop() when users cancel mid-effect
Pass a queue name when clearing custom serial task queues
Inspect .queue("fx").length while debugging stacked effects
Use named queues to separate effects from non-animation work
❌ Don’t
Expect .clearQueue() alone to halt the current animation
Confuse it with .dequeue() — dequeue runs the next item
Assume .stop() clears custom .queue() callbacks
Clear queues on elements you are about to remove without calling .stop()
Forget that only pending items are removed — finished steps stay done
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .clearQueue()
Drop pending queue work on demand.
5
Core concepts
⏹01
clearQueue
Drop pending
API
📚02
fx default
Effects queue
Queue
🔗03
Chainable
Returns jQuery
Return
⚠04
+ stop()
Halt current too
Pattern
📈05
Custom names
Non-fx queues
Advanced
❓ Frequently Asked Questions
.clearQueue() removes every function on the specified queue that has not yet run. It does not undo animations already in progress — it empties the waiting list so chained effects and queued callbacks never start.
An optional string naming which queue to clear. It defaults to "fx" — jQuery's standard effects queue used by .show(), .animate(), and similar methods. Pass a custom name like "tasks" to clear queues created with .queue("tasks", fn).
For the fx queue, both remove pending items. .stop(true) is animation-focused and can also jump the current effect to its end state when combined with jumpToEnd. .clearQueue() is queue-generic — it removes any pending function added via .queue(), not only animation steps.
No. It only removes functions that have not started. The effect currently executing continues until it finishes or you call .stop(). The official jQuery demo calls both myDiv.clearQueue() and myDiv.stop() on Stop for that reason.
Yes. That is a key difference from .stop(). When you .queue(function() { ... }) a non-animation callback onto fx or a named queue, .clearQueue() removes those pending functions. .stop() is intended for animations, not arbitrary queued work.
Often yes when the user cancels mid-animation: .clearQueue() drops everything waiting to run; .stop() halts the effect currently playing. For rapid-click guards before starting fresh animations, .clearQueue() alone (or .stop(true)) is usually enough.
Did you know?
jQuery’s official .clearQueue() demo chains .show(), a five-second .animate(), two .queue() class-toggle callbacks, and .slideUp() — then clears everything with one Stop click. The API documentation pairs clearQueue() with stop() because clearing the waiting list alone leaves the current animation running until you explicitly stop it.