0

In this code:

$('#bomb').animate({
    'top': '+=200px'
}, 3000)
    .queue(function() {
        $('#explosion').fadeIn();
        $(this).dequeue();
    });

$('#bomb').fadeOut('fast');

If I replace $(this).dequeue() with next(), it appears to do the same thing. What exactly is the difference?

CaptSaltyJack
  • 15,283
  • 17
  • 70
  • 99

1 Answers1

1

The passing of "next" to the function was added in 1.4, I think more just as a way to make code more understandable. I think in the case you mentioned you should use next because it's more readable. There are however situations when you have to use dequeue.

The fx queue is a special case as it will automatically dequeue the first element from the queue if it is empty and something is queued. Normally this is not the case.

Consider this:

$("#something").queue("myqueue", function(){/*dostuff*/});

This alone will never execute the function passed. A call to dequeue is required to start the queue moving:

$("#something").queue("myqueue", function(){/*dostuff*/}).dequeue("myqueue");
James Montagne
  • 77,516
  • 14
  • 110
  • 130