jQuery .clearQueue() Method

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

What You’ll Learn

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

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

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.

📝 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();

⚡ Quick Reference

GoalCode
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)

📋 .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

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();
});
Try It Yourself

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 );
Try It Yourself

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).

jQuery
var $el = $( "#worker" );

$el.queue( "tasks", function( next ) {
  console.log( "task 1" );
  next();
});
$el.queue( "tasks", function( next ) {
  console.log( "task 2" );
  next();
});
$el.queue( "tasks", function( next ) {
  console.log( "task 3" );
  next();
});

console.log( "before:", $el.queue( "tasks" ).length );
$el.clearQueue( "tasks" );
console.log( "after:", $el.queue( "tasks" ).length );
Try It Yourself

How It Works

Custom queue names isolate work from the default fx pipeline. .clearQueue("tasks") empties only that queue — animations on fx continue unaffected.

Example 4 — Rapid Click Guard

Before starting a new animation, clear pending fx steps so repeated clicks do not stack competing effects.

jQuery
$( "#toggle" ).on( "click", function() {
  var $panel = $( "#panel" );

  $panel.clearQueue().stop();
  $panel.animate({ height: "toggle" }, 300 );
});
Try It Yourself

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.

jQuery
var $el = $( "#target" );

$el.fadeIn( 400 );
$el.animate({ opacity: 0.5 }, 800 );
$el.fadeOut( 400 );

var pending = $el.queue( "fx" );
console.log( "pending count:", pending.length );

$el.clearQueue();
console.log( "after clearQueue:", $el.queue( "fx" ).length );
Try It Yourself

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.

🚀 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.

📝 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.

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

Bottom line: Learn .clearQueue() alongside .stop() and .queue() to manage animation pipelines confidently in legacy and modern jQuery apps.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about .clearQueue()

Drop pending queue work on demand.

5
Core concepts
📚 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.

Next: jQuery Effects Methods

Learn custom CSS animation with .animate() — duration, easing, queue:false, and step callbacks.

Effects hub →

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