jQuery .queue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Effects

Definition

.queue() (since jQuery 1.2) shows, adds to, or replaces the function queue on matched elements. The default queue name is "fx" — the effects pipeline used by .animate(), .fadeIn(), and similar methods.

Syntax

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

jQuery
$el.queue()                 // read → Array (default "fx")
$el.queue(function (next) { // add step
  // work…
  next();                   // or $(this).dequeue()
});
$el.queue("fx", []);        // replace / empty pending

// $("#foo").slideUp().fadeIn()
// → slideUp runs now; fadeIn waits on fx
CallWhat it does
queueNameDefaults to "fx"
callbackFunction to append; gets next since 1.4
newQueueArray of functions (use [] to empty)
Return (read)Array of pending functions
Return (add/replace)jQuery object (chainable)

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

Parameters

ParameterDescription
readUsed in Return (read). Array of pending functions
add/replaceUsed in Return (add/replace). jQuery object (chainable)

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Read fx Queue Length

Official idea: poll .queue("fx").length while a chain runs.

jQuery
var $box = $("#box");

function runIt() {
  $box
    .fadeIn("slow")
    .animate({ marginLeft: 120 }, 1500)
    .fadeOut("slow")
    .fadeIn(800, runIt);
}

function showIt() {
  $("#len").text($box.queue("fx").length);
  setTimeout(showIt, 100);
}

runIt();
showIt();
Try It Yourself

How It Works

  1. Chain. Each effect pushes a step onto fx.
  2. Read. .queue("fx") returns the pending function array.
  3. Length. .length is how many steps still wait.

Example 2 — Add Queued Steps Mid-Chain

Official pattern: insert custom work between animations; call .dequeue().

jQuery
$("#run").on("click", function () {
  $("#box")
    .fadeIn("slow")
    .animate({ marginLeft: 120 }, 1500)
    .queue(function (next) {
      $(this).text("Mid-step");
      next();
    })
    .animate({ marginLeft: 0 }, 500)
    .queue(function (next) {
      $(this).text("Done");
      next();
    })
    .fadeOut();
});
Try It Yourself

How It Works

  1. Insert. .queue(fn) places a step after the previous effect.
  2. Work. Update the DOM inside the callback.
  3. Advance. Call next() (or .dequeue()).

Example 3 — After slideUp Without a Callback Param

Same timing as slideUp(callback), but the step is attached with .queue().

jQuery
$("#run").on("click", function () {
  var $foo = $("#foo").stop(true, true).show();

  $foo.slideUp();
  $foo.queue(function (next) {
    $("#status").text("Animation complete.");
    next();
  });
});
Try It Yourself

How It Works

  1. Effect. slideUp() runs with no complete handler.
  2. Queue. The next statement appends a function to fx.
  3. Order. That function waits until slideUp finishes.

Frequently Asked Questions

.queue() shows, adds to, or replaces the function queue on matched elements. With no callback or array it returns an Array of pending functions. With a callback it appends that function. With an array it replaces the entire queue contents.
1) .queue([queueName]) — returns Array (default queueName "fx"). 2) .queue([queueName], callback) — adds a function; returns jQuery; callback receives next() since 1.4. 3) .queue([queueName], newQueue) — replaces the queue with an Array (e.g. [] to empty it).
"fx" is jQuery’s default effects queue. Methods like .slideUp(), .fadeIn(), and .animate() push steps onto fx and run them one at a time. Chaining $("#foo").slideUp().fadeIn() runs slideUp first; fadeIn waits until slideUp finishes.
When jQuery runs a function you added with .queue(fn), it pauses until you signal completion. Call $(this).dequeue() or the next() argument so the following step can run. Without that signal, the chain stalls.
.queue(fn) adds a standalone step at the end of the queue — useful when the previous method has no callback parameter. An animate/slideUp callback runs when that specific animation completes. Both can sit mid-chain; .queue() works with any chained method.
It replaces the fx queue with an empty array, removing all pending functions that have not yet run. Pair with .stop() to also halt the current effect. .clearQueue() is a dedicated API for clearing pending items.

Next: .dequeue() Run the Next Queued Function

Run the next function in a queue — the partner to .queue() for custom pipelines.

.dequeue() Run the Next Queued Function 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