jQuery Queue is used to manage and control a sequence of functions that execute one after another on selected elements. It is most commonly used with animations, but it can also manage custom tasks.
next() to continuefxjQuery provides the .queue() and .dequeue() methods to work with queues. Functions are executed sequentially.
// Syntax of jQuery queue method
$(selector).queue(function(next){
console.log("Task running");
next();
});
// Using jQuery queue to run tasks sequentially
$("#box").queue(function(next){
$(this).css("background","red");
next();
}).queue(function(next){
$(this).css("width","200px");
next();
}).queue(function(next){
$(this).css("height","200px");
next();
});
The element changes its background color first, then its width, and finally its height. Each step waits for the previous one to complete.
Watch the status bar to see how the queue processes each function in order.
next() inside queue functions