Code has been added to clipboard!

How and When to Use jQuery .queue(), .dequeue(), and .clearQueue()

Reading time 2 min
Published Jul 3, 2019
Updated Sep 30, 2019

jQuery queue: Main Tips

  • jQuery animation queue represents effects waiting to be executed.
  • The .queue() method shows the functions queued on the selected items' default queue (fx), or other queues.
  • The .dequeue() method removes a function from the specified queue and executes it.
  • The .clearQueue() method removes all animations from the queue on the selected element.

Using the .queue() Method

The jQuery .queue() reveals the methods queued on the selected items' default fx queue, or other queues. After clicking the button in the example below, animations start, and the total number of them is displayed:

The syntax for jQuery .queue() is as follows:

$("selector").queue(queue);

Explanation of .dequeue()

What does .dequeue() do? It removes a function from the specified jQuery animation queue and executes it. In the example below, you can see the method changing the size and color of the element:

Here is the syntax you would use for jQuery .dequeue():

$("selector").dequeue(queue);

Introducing .clearQueue()

To remove all animations from the queue on the selected element, use .clearQueue(). In the example below, you may start the first animation, and prevent the second one from executing by clicking the button:

Example
$("button").click(() => {
    $("div").clearQueue();
});

Here is the syntax you would use for this method:

$("selector").clearQueue(queue);

Note: in all of these cases, the syntax takes a single argument, defining the name of the jQuery animation queue. The default value is the standard effects queue fx.

Learn jQuery
Introduction
Selectors
Events
Event Methods
Download
Callback
Chaining
Get and Set
Add Element
Remove Element
Traverse
Parent
Children
Sibling Traverse
Filtering
jQuery AJAX
Effects
Show and Hide
Fade Effect
Slide Effect
Animate Effect
Manipulate CSS
Width and Height
.addClass()
.after()
.animate()
.append()
.appendTo()
.attr()
.before()
.bind() (deprecated)
.blur()
.change()
.click()
.clone()
.css()
.dblclick()
.delay()
.delegate() and .undelegate() (deprecated)
.detach()
.empty()
.end()
.error() (deprecated)
.fadeIn()
.fadeOut()
.fadeTo()
.fadeToggle()
.finish()
.focus()
.focusIn()
.focusOut()
.hasClass()
.height()
.hide()
.hover()
.html()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.keypress()
.keyup()
.live() and .die() (deprecated)
.load() (deprecated)
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseout()
.mouseover()
.mouseup()
.off()
.offset()
.offsetParent()
.on()
.one()
.outerHeight()
.outerWidth()
.position()
.prepend()
.prependTo()
.prop()
.proxy()
.queue()
.ready()
.remove()
.removeAttr()
.removeClass()
.removeProp()
.replaceAll()
.replaceWith()
.resize()
.scroll()
.scrollLeft()
.scrollTop()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.submit()
.text()
.toggle()
.toggleClass()
.trigger()
.triggerHandler()
.unbind() (deprecated)
.unload() (deprecated)
.unwrap()
.val()
.width()
.wrap()
Event Properties
event.currentTarget
event.preventDefault()
event.relatedTarget
event.stopImmediatePropagation()
event.stopPropagation()
event.target
event.timeStamp
event.type
event.which
jQuery .find()
jQuery .keydown()
jQuery.noConflict()
pageY and pageX