Display the length of a queue in a <span> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/*from w w w . java2 s. com*/ <script> $(document).ready(function(){ $("button").click(function(){ let div = $("div"); div.animate({height: 300}, "slow"); div.animate({width: 300}, "slow"); div.animate({height: 100}, "slow"); div.animate({width: 100}, "slow"); $("span").text(div.queue().length); }); }); </script> </head> <body> <button>Start Animation</button> <p>The queue length is: <span></span></p> <div style="width:50px;height:50px;position:absolute;left:10px;top:100px;background-color:red;"> </div> </body> </html>
The queue()
method returns the queue of functions to be executed on the selected elements.
An element can have several queues.
$(selector).queue(queueName)
Parameter | Optional | Description |
---|---|---|
queueName | Optional. | the name of the queue Default is "fx", the standard effects queue |