jQuery .queue() Method

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is jQuery.queue()?

jQuery.queue(element, …) (alias $.queue) shows or changes the function queue on a DOM element (added in jQuery 1.3). Default queue name is "fx".

Remember
// 1) Read (returns Array)
$.queue(element [, queueName])

// 2) Append a function
$.queue(element, queueName, callback)

// 3) Replace the whole queue
$.queue(element, queueName, newQueueArray)

var n = $.queue($("#box")[0], "fx");
console.log(n.length);          // pending steps

$.queue(el, "fx", function () {
  $(this).text("mid");
  $.dequeue(this);              // continue!
});
NeedUse
Low-level inspect / add$.queue(elem, …)
Everyday API$(elem).queue()
Continue after a custom step$.dequeue(elem)

How to Use jQuery.queue()

Inspect length, append a step, or replace the queue — always finish custom steps.

  1. Get a raw DOM node ($el[0] or this in a callback).
  2. Read with $.queue(el, "fx") and check .length.
  3. Append with $.queue(el, "fx", fn) — end fn with $.dequeue(this).
  4. Clear pending steps with $.queue(el, "fx", []) (often plus .stop()).
PieceRequired?Role
elementYesRaw DOM element that owns the queue
queueNameUsualDefaults to "fx" when reading
callback / newQueueOptionalAppend one function, or replace with an array

Pseudocode

Pseudocode
function queue(element, name = "fx", third):
    if third is missing:
        return array of pending functions
    if third is a function:
        append third to element.queues[name]
        return the queue array
    if third is an array:
        replace element.queues[name] with third
        return the queue array

// After appending a custom step:
callback must eventually call dequeue(element, name)

Cheat Sheet

Keep these facts handy while working with jQuery queues.

TopicDetail
SyntaxjQuery.queue(element, …) / $.queue(…)
SincejQuery 1.3
Default queue"fx" (effects)
ReadReturns Array — use .length
Append$.queue(el, "fx", fn) then $.dequeue
Clear pending$.queue(el, "fx", []) or .clearQueue()
Twin.queue()

Live Preview

Start a short fade chain, then inspect length, append a step, or clear with [].

Demo box: Ready

Result
Pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Official: Show Queue Length

Read the fx queue array and print .length.

jQuery
$("#box").fadeOut(800).fadeIn(800).fadeOut(800);

var n = jQuery.queue($("#box")[0], "fx");
console.log("Queue length is: " + n.length);
Try It Yourself

How It Works

  1. Enqueue. Each fade call adds a step to the fx queue.
  2. Inspect. jQuery.queue(el, "fx") returns the pending array.
  3. Length. n.length is how many steps are still waiting or in flight.
  4. Timing. Check again later and the number may drop as steps finish.

Example 2 — Official: Append a Custom Function

Add a mid-step with $.queue, then continue with $.dequeue.

jQuery
var el = $("#box")[0];

$("#box").fadeOut(400);

jQuery.queue(el, "fx", function () {
  $(this).text("Mid step");
  jQuery.dequeue(this);
});

$("#box").fadeIn(400);
Try It Yourself

How It Works

  1. Start. fadeOut pushes the first fx step.
  2. Append. $.queue(el, "fx", fn) adds your custom work.
  3. Work. Inside fn, update the text (or class).
  4. Continue. $.dequeue(this) unlocks fadeIn.

Example 3 — Official: Replace Queue with []

Drop pending steps by replacing the queue with an empty array.

jQuery
var el = $("#box")[0];

$("#box").fadeOut(2000).fadeIn(2000).fadeOut(2000);

// Later — cancel waiting steps:
jQuery.queue(el, "fx", []);
$("#box").stop();
Try It Yourself

How It Works

  1. Stack up. Several fades fill the fx queue.
  2. Replace. $.queue(el, "fx", []) empties pending functions.
  3. Stop current. .stop() ends the animation already running.
  4. Alt API. Prefer .clearQueue() when using the instance style.

Example 4 — Custom Queue Name

Use a named queue separate from "fx".

jQuery
var el = document.getElementById("box");

$.queue(el, "tasks", function (next) {
  $(el).text("Step 1");
  setTimeout(next, 400);
});
$.queue(el, "tasks", function () {
  $(el).text("Step 2");
  $.dequeue(el, "tasks");
});

$.dequeue(el, "tasks");  // start
Try It Yourself

How It Works

  1. Name. "tasks" is independent of the effects queue.
  2. Append twice. Two callbacks wait in order.
  3. Kickoff. First $.dequeue(el, "tasks") starts the pipeline.
  4. Finish. Each step continues with next or $.dequeue.

Example 5 — $.queue vs .queue()

Same mid-step job — static utility vs instance method.

jQuery
// Static (DOM element first):
$.queue($("#a")[0], "fx", function () {
  $(this).text("via $.queue");
  $.dequeue(this);
});

// Instance (preferred day to day):
$("#b").queue(function (next) {
  $(this).text("via .queue()");
  next();
});
Try It Yourself

How It Works

  1. Static. $.queue(el, "fx", fn) needs a raw node and $.dequeue.
  2. Instance. .queue(fn) runs on a collection; next() continues.
  3. Same queue. Both talk to the same fx pipeline under the hood.
  4. Prefer. Official docs recommend .queue() for everyday UI code.

Edge Cases & Pitfalls

Check these before manipulating queues by hand.

stall

Appended callbacks must continue

If you add a function with $.queue and never call $.dequeue / next, later steps freeze.

element

Pass a DOM node, not a jQuery object

Use $el[0] or .get(0). The static API expects an element.

clear

[] clears pending — not the current frame

Emptying the queue drops waiting steps. Pair with .stop() to halt the animation already running.

name

Match queue names

Custom queues need the same string on queue and dequeue. Default "fx" is for effects.

Browser Support

jQuery.queue() is available since jQuery 1.3+ in all modern browsers with jQuery loaded. It is a jQuery utility (not a native browser API).

✓ jQuery 1.3+ · Stable

jQuery.queue()

Works in Chrome, Firefox, Safari, and Edge whenever jQuery 1.3+ is loaded. Prefer $(el).queue() for everyday animation chains.

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
$.queue() jQuery 1.3+

Bottom line: Use $.queue(el, …) when you hold a raw DOM node. For most UI code, call $(el).queue() and finish custom steps with dequeue / next.

Performance Notes

ApproachCostBest for
$.queue(el) readO(1)Checking pending length
Append callbackO(1)One custom mid-step
Very long fx stacksUI-boundKeep chains short; clear with [] / .stop()

Queue bookkeeping is cheap. Cost comes from the animations and timers you schedule — keep queues short and always finish custom steps.

Key Takeaways

  • Role: inspect, append, or replace an element’s function queue.
  • Continue: appended callbacks need $.dequeue.
  • Clear: $.queue(el, "fx", []) drops pending steps.
  • Prefer: .queue() day to day.

One line: $.queue reads or rewrites an element’s function list — append carefully, and always dequeue.

Frequently Asked Questions

jQuery.queue() shows or changes the function queue on a DOM element. With only an element (and optional queueName) it returns an Array of pending functions. With a callback it appends that function. With an array it replaces the whole queue. Added in jQuery 1.3. Prefer $(element).queue() for everyday code.
1) jQuery.queue(element [, queueName]) — returns Array (inspect length). 2) jQuery.queue(element, queueName, callback) — adds a function to the end. 3) jQuery.queue(element, queueName, newQueue) — replaces the queue with that Array (use [] to clear pending steps).
Same jobs, different call shape. jQuery.queue(elem, …) takes a raw DOM element first. .queue() is called on a jQuery collection. Official docs recommend .queue() day to day; jQuery.queue() is the low-level utility.
"fx" is jQuery’s default effects queue. .animate(), .fadeOut(), and similar methods push steps onto fx and run them one at a time. Omitting queueName when reading defaults to fx.
A function you append with jQuery.queue(el, "fx", fn) pauses the pipeline until you finish. Call jQuery.dequeue(this) (or $(this).dequeue() / next()) so the next step runs.
It replaces the fx queue with an empty array, dropping pending functions that have not started. Pair with .stop() when canceling animations. .clearQueue() is the dedicated instance API for clearing pending items.

Next: jQuery.dequeue()

Learn how to run the next function on an element’s queue.

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

9 people found this page helpful