jQuery .dequeue() Run the Next Queued Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Effects

Definition

.dequeue() (since jQuery 1.2) removes the next function from a queue and runs it immediately. Default queue is "fx". Returns the jQuery object for chaining.

Syntax

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

jQuery
$el.dequeue();                 // advance fx
$el.dequeue("tasks");          // advance a named queue

// Classic custom step:
$el.queue(function () {
  $(this).addClass("done").dequeue();
});

// Modern equivalent:
$el.queue(function (next) {
  $(this).addClass("done");
  next();
});
CallWhat it does
.dequeue() Run the Next QueuedLearn jQuery .dequeue(): execute the next fx or named-queue function since 1.2, compare with next(), fix stalled custom .queue() callbacks, and keep animation chains moving.

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

Parameters

ParameterDescription
Step 1Chain effects on an element (.animate(…)).
Step 2Insert a custom step with .queue(function () { … }).
Step 3Inside that function, do non-animation work (toggle a class, update text).

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 Animate + toggleClass

From the jQuery docs: insert a class toggle between animates and continue with .dequeue().

jQuery
$("button").on("click", function () {
  $("div")
    .animate({ left: "+=200px" }, 2000)
    .animate({ top: "0px" }, 600)
    .queue(function () {
      $(this).toggleClass("red").dequeue();
    })
    .animate({ left: "10px", top: "30px" }, 700);
});
Try It Yourself

How It Works

  1. Animate. Two moves queue on fx and auto-advance.
  2. Custom step. .queue() runs your callback mid-chain.
  3. toggleClass. Non-animation work happens here.

Example 2 — Stalled Queue vs Fixed

Skip .dequeue() and the later animate never runs. Add it and the round-trip completes.

jQuery
// Broken — queue stalls after the class change
$box
  .animate({ marginLeft: 100 }, 800)
  .queue(function () {
    $box.addClass("highlight");
  })
  .animate({ marginLeft: 0 }, 800);

// Fixed — dequeue continues the chain
$box
  .animate({ marginLeft: 100 }, 800)
  .queue(function () {
    $box.addClass("highlight");
    $(this).dequeue();
  })
  .animate({ marginLeft: 0 }, 800);
Try It Yourself

How It Works

  1. Pause. Custom .queue() stops auto-advance.
  2. Broken. No continue signal → later animate waits forever.
  3. Fixed. .dequeue() removes the next step and runs it.

Example 3 — Modern next() Pattern

Same continue behavior: pass next into the queue callback and call it when done.

jQuery
$("#panel")
  .fadeIn(400)
  .queue(function (next) {
    $(this).text("Loaded!");
    next();
  })
  .fadeOut(400);
Try It Yourself

How It Works

  1. fadeIn. Standard effect auto-dequeues when done.
  2. queue. Callback receives next.
  3. Work. Update the text while the chain is paused.

Frequently Asked Questions

.dequeue() removes the next function from the specified queue and executes it immediately. It advances the queue by one step — unlike .clearQueue(), which drops all pending items without running them.
An optional string naming which queue to advance. It defaults to "fx" — jQuery’s standard effects queue. Pass a custom name like "tasks" to dequeue from queues created with .queue("tasks", fn).
When jQuery runs a function you added with .queue(), it pauses the pipeline until you signal completion. Calling $(this).dequeue() or next() tells jQuery to run the following step. Without that signal, the queue stalls and later animations never start.
They achieve the same goal. next() is the modern pattern: .queue(function(next) { … next(); }). .dequeue() is the classic style: .queue(function() { $(this).dequeue(); }). Both continue the queue.
Yes for standard effects. jQuery automatically dequeues after each .animate(), .fadeIn(), and similar fx step. You only need manual .dequeue() (or next()) inside custom functions added with .queue(fn).
A jQuery object — the same collection you called it on. You can chain further methods, though it is most often called inside a queued callback to resume the pipeline.

Next: .clearQueue() Remove Pending Queue Items

Drop pending queue items without running them — the counterpart to .dequeue().

.clearQueue() Remove Pending Queue Items 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