When I use the fade/slide/animate functions in jQuery the callback gets called multiple times for each element the effect is applied to. This is by design of course. I jus
Try taking a look at the jQuery documentation for .promise()
This should work:
$('div').fadeOut(1000).promise().done(function() {
alert('all done');
});
As usualy, the jQuery documentation on this is really vague. But I'm not sure I could do
That would produce the alert when the fadeOut on the last element was called. That would not necessarily be the last fadeOut.
var numDivs = $('div').length;
$('div').fadeOut(1000, function() {
if( --numDivs > 0 ) return;
alert('this is the final fadeout to complete');
});
Check it out on JSFiddle
$("div:not(:last)").fadeOut(1000);
$("div:last").fadeOut(1000, function() {
alert("Hey!");
});