.queue()

Syntax


.queue([queueName]) 
.queue([queueName], newQueue) 
.queue([queueName], callback)
queueName (optional)
The name of the queue. Defaults to fx, the standard effects queue
newQueue
An array of functions to replace the current queue contents
callback
The new function to add to the queue

Return value

.queue([queueName]) returns an array of the functions currently in the first element's queue.

(.queue([queueName], newQueue) and .queue([queueName], callback)) returns the jQuery object, for chaining purposes.

Description

Manipulate the queue of functions to be executed on the matched elements.

Examples

Queue a custom function

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            $(document.body).click(function () {
              $("div").show("slow");
              $("div").animate({left:'+=20'},2000);
              $("div").queue(function () {
                $(this).addClass("newcolor");
                $(this).dequeue();
              });
              $("div").animate({left:'-=20'},500);

              $("div").slideUp();
            });
        });
    </script>
<style>
  div { margin:3px; width:50px; position:absolute;
        height:50px; left:10px; top:30px; 
        background-color:yellow; }
  div.red { background-color:red; }
  
</style>
  </head>
  <body>
    <body>
        Click here...
          <div></div>
    </body>
</html>
  
Click to view the demo

Replaces the queue of all matched element with this new queue (the array of functions).

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(document.body).click(function () {
              $("div").show("slow");
              $("div").animate({left:'+=20'},2000);
              $("div").queue(function () {
                $(this).addClass("newcolor");
                $(this).dequeue();
              });
              $("div").animate({left:'-=20'},500);

              $("div").slideUp();
            });
        });
    </script>
<style>

  div { margin:3px; width:50px; position:absolute;
        height:50px; left:10px; top:30px; 
        background-color:yellow; }
  div.red { background-color:red; }
  
</style>
  </head>
  <body>
    <body>
        Click here...
          <div></div>
    </body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    jQuery  

Effect:
  1. jQuery Effect
  2. .animate()
  3. .css() does animation
  4. .clearQueue()
  5. .delay()
  6. .dequeue()
  7. $.extend()
  8. .fadeIn()
  9. .fadeOut()
  10. .fadeTo()
  11. .hide()
  12. .queue()
  13. .show()
  14. .slideDown()
  15. slideToggle
  16. .slideUp()
  17. .stop()
  18. .toggle()