Jurudocs
Jurudocs

Reputation: 9175

How to know when a jquery effect ends if there are mutiple elements which are animated

Given the following example: If 5 <li> elements are found, the callback fires an alert 5 times...

Is there an easy way to find out when the animation is really over and just fire once?

$(this).parent().siblings('li').slideUp(500,function(){
    alert 
});

Upvotes: 4

Views: 215

Answers (1)

gdoron
gdoron

Reputation: 150293

$.when($(this).parent().siblings('li').slideUp(500))
 .then(function() {
            alert('Finished!');
       });

Working DEMO

when docs:

Description: Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events.

Upvotes: 8

Related Questions