queue(), dequeue() and clearQueue()
Queues are the foundation for all animations in jQuery , they allow a series functions to be executed asynchronously on an element. You can use them for any purpose you like. They are an array of functions stored on a per element basis, using jQuery.data() . They are First-In-First-Out (FIFO).
You can add a function to the queue by calling .queue() , and you remove (by calling) the functions using .dequeue() . If you write multiple animate method calls one after the other, jQuery creates an 'internal' queue and adds these method calls to it. Then it runs those animate calls one by one.
The queue length is :
Retrieving/Setting the queue
You can retrieve a reference to a jQuery queue by calling .queue() without a function argument. You can use the method if you want to see how many items are in the queue. You can use push, pop, unshift, shift to manipulate the queue in place. You can replace the entire queue by passing an array to the .queue() function.
jQuery does not have any insight into how the queue items function; as such, we need to explicitly tell jQuery when to move to the next item in the queue. This can be done with the the dequeue() method. With this method, you can call the dequeue() method on the given element with the given queue name. In a queue there will be a several function waiting to run dequeue() used to remove the top function from the queue and execute that function.
To ensure that process is running, you must make sure that this method should be called only after the addition of a function with queue() method . If nothing is passed as an argument, then the deQueue method will remove the functions from the standard effects queue.
The queue length is :
When the .clearQueue() method is called, all functions on the queue that have not been executed are removed from the queue. If there's a current animation (for example) taking place, it is not affected. But any queued items will not execute. When used without an argument, .clearQueue() removes the remaining functions from fx, the standard effects queue.
In this way dequeue() is similar to .stop(true). However, while the .stop() method is meant to be used only with animations, .clearQueue() can also be used to remove any function that has been added to a generic jQuery queue with the .queue() method.