jQuery .clearQueue() Remove Pending Queue Items

Beginner
5 min read
Updated: Nov 2026
3 examples
Effects

Definition

.clearQueue() (since jQuery 1.4) removes every function on a queue that has not yet run. Without an argument it clears "fx", the standard effects queue. Returns the jQuery object for chaining.

Syntax

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

jQuery
$el.clearQueue();              // clear pending fx items
$el.clearQueue("tasks");       // clear a named queue
$el.clearQueue().stop();       // drop waiting + halt current effect

// Waiting list emptied · current effect still runs unless .stop()
CallWhat it does
.clearQueue() Remove Pending Queue ItemsLearn jQuery .clearQueue(): remove waiting fx or named-queue functions since 1.4, compare with .stop(true) and .stop(), clear custom .queue() callbacks, and cancel animation chains safely.

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

Parameters

ParameterDescription
Step 1Select the animated element ($("#box")).
Step 2Call .clearQueue() (or .clearQueue("name") for a custom queue).
Step 3Optionally call .stop() to halt the effect already in progress.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official Start/Stop Demo

From the jQuery docs: build a long chain, then clear pending steps and stop the current effect.

jQuery
$("#start").on("click", function () {
  var myDiv = $("div.box");
  myDiv.show("slow");
  myDiv.animate({ left: "+=200" }, 5000);
  myDiv.queue(function () {
    $(this).addClass("newcolor").dequeue();
  });
  myDiv.animate({ left: "-=200" }, 1500);
  myDiv.queue(function () {
    $(this).removeClass("newcolor").dequeue();
  });
  myDiv.slideUp();
});

$("#stop").on("click", function () {
  var myDiv = $("div.box");
  myDiv.clearQueue();
  myDiv.stop();
});
Try It Yourself

How It Works

  1. Start. Several effects and .queue() callbacks are chained onto fx.
  2. Waiting. Only one step runs at a time; the rest sit pending.
  3. clearQueue. Removes every function that has not started.

Example 2 — .clearQueue() vs .stop(true)

Both can empty pending fx items. Check queue length right after each call.

jQuery
function setupBox() {
  var $box = $("#box").css({ width: 40 });
  $box.stop(true, true).clearQueue();
  $box.animate({ width: 200 }, 2000);
  $box.queue(function (next) {
    $("#log").append("custom callback queued\n");
    next();
  });
  return $box;
}

$("#run-stop").on("click", function () {
  var $box = setupBox();
  $box.stop(true);
  $("#log").text("after stop(true): " + $box.queue("fx").length);
});

$("#run-clear").on("click", function () {
  var $box = setupBox();
  $box.clearQueue();
  $("#log").text("after clearQueue: " + $box.queue("fx").length);
});
Try It Yourself

How It Works

  1. Setup. One animate plus a custom queued callback.
  2. stop(true). Clears the fx queue (animation-oriented).
  3. clearQueue. Also clears pending fx items — and works on named queues.

Example 3 — Clear a Named Custom Queue

Pass a queue name to clear non-fx work built with .queue("tasks", fn).

jQuery
var $el = $("#worker");
$el.queue("tasks", function (next) { next(); });
$el.queue("tasks", function (next) { next(); });
$el.queue("tasks", function (next) { next(); });

$("#clear").on("click", function () {
  var before = $el.queue("tasks").length;
  $el.clearQueue("tasks");
  var after = $el.queue("tasks").length;
  $("#log").text("before: " + before + "\nafter: " + after);
});
Try It Yourself

How It Works

  1. Name. Functions are stored on the "tasks" queue, not fx.
  2. Clear. .clearQueue("tasks") removes only that queue’s pending items.
  3. fx untouched. Animations on fx are not affected.

Frequently Asked Questions

.clearQueue() removes every function on the named queue that has not yet run. It empties the waiting list so chained effects and queued callbacks never start. It does not undo an animation that is already in progress.
An optional string naming which queue to clear. It defaults to "fx" — jQuery’s standard effects queue used by .animate(), .fadeIn(), .slideUp(), and similar methods. Pass a custom name like "tasks" to clear queues built 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 when combined with jumpToEnd. .clearQueue() is queue-generic — it removes any pending function added via .queue(), not only animation steps.
No. Only functions that have not started are removed. The effect currently executing continues until it finishes or you call .stop(). The official jQuery demo calls both .clearQueue() and .stop() on Stop for that reason.
Yes. That is a key difference from .stop(). When you queue a non-animation callback with .queue(fn), .clearQueue() removes pending ones. .stop() is meant for animations, not arbitrary queued work.
Often yes when canceling mid-animation: .clearQueue() drops everything waiting; .stop() halts the effect currently playing. For a rapid-click guard before a new animation, .clearQueue().stop() (or .stop(true)) is a common pattern.

Next: .promise() Method

Browse the full effects toolkit — animate, fade, slide, queue, and more.

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

10 people found this page helpful