I have the following structure
$('foo').click( function() {
var bool = false;
$('bar').animate( function() {
//bool = something
});
return bool;
});
But because the animation callback is async, bool is never set properly. Moving the return statement into the callback doesn’t make sense. How can I get the return statement to wait until the animation completes?
It isn’t possible, the return will happen immediately—there is no way to delay it. Try doing it this way instead: