jQuery API

.clearQueue()

.clearQueue( [queueName] ) Returns: jQuery

Description: Remove from the queue all items that have not yet been run.

  • version added: 1.4.clearQueue( [queueName] )

    queueNameA string containing the name of the queue. Defaults to fx, the standard effects queue.

When the .clearQueue() method is called, all functions on the queue that have not been executed are removed from the queue. When used without an argument, .clearQueue() removes the remaining functions from fx, the standard effects queue. In this way it 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.

Example:

Empty the queue.

<!DOCTYPE html>
<html>
<head>
  <style>
div { margin:3px; width:40px; height:40px;
    position:absolute; left:0px; top:30px; 
    background:green; display:none; }
div.newcolor { background:blue; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <button id="start">Start</button>
<button id="stop">Stop</button>
<div></div>
<script>$("#start").click(function () {
  $("div").show("slow");
  $("div").animate({left:'+=200'},5000);
  $("div").queue(function () {
    $(this).addClass("newcolor");
    $(this).dequeue();
  });
  $("div").animate({left:'-=200'},1500);
  $("div").queue(function () {
    $(this).removeClass("newcolor");
    $(this).dequeue();
  });
  $("div").slideUp();
});
$("#stop").click(function () {
  $("div").clearQueue();
  $("div").stop();
});</script>

</body>
</html>

Demo:

Support and Contributions

Need help with .clearQueue() or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to .clearQueue()? Report it to the jQuery core team.

Found a problem with this documentation? Report it to the jQuery API team.

* All fields are required
  • kaki
    why don't you post some examples for .clearQueue() rather than discuss about label stop, pause ...
  • It is not a 'pause'. If you hit start and stop in quick succession then you will see a horizontal scroll bar soon. That is because each time you hit start, you are stating the full effect and it not a pause.
  • @Andrew I think you are wrong... if you press stop it stops the animation that you are running in that moment.
  • Andrew
    It would be clearer to label these buttons "Play" and "Pause", since "pausing" makes clear that things can continue.
  • David Rodrigues
    You can't pause, you can stop really. Try "play", on middle of animation, press "stop", then "play" again, and do this everytime. You see that this don't is pausing, but stopping.
    Bye.
  • I think what Andrew was meaning is that the button they labeled 'Stop' acts more like a pause feature more than a stop feature in media situations. Usually when you press stop, then press play, it will begin from the beginning. While pressing pause acts like this example where the animation is not reset and pressing play resumes the animation.

    I agree that the button should be labeled Pause, but it's just an example.
  • David Rodrigues
    Yeah, I understand. But the "Stop" button act as "stop" button. Try and you will see: press play, after 2 seconds, press stop, play, after 2 seconds, press stop, ... And you will see that the Play is wrong, it don't reset the animation, only start a new from the current left padding.
  • Grafsl
    In FF 3.6.13 "Stop" button acts like Pause
  • Jon
    I justed tested this is FF 3.6.13 and got the opposite behavoiur. I am seeing it as the example explains it.

    Clicking start runs the animation.
    Click stop stops the animation.

    ** Clicking start again starts the animation again from the very beggining but using whatever position the squaer was in when you lcoked stop as the new start position **

    This can be seen clearly if you stop the animation half-way on it's way back. AFter clicking start the square moves right instead of to the left which is what would happen if this was a 'pause' action.