jQuery promise() function (wait for multiple things to happen before moving on)

I just encountered a situation in which I needed to wait for multiple animations to complete before continuing execution, but I only wanted the next command to execute once (as opposed to once per animating element).

Normally, I would do something like this:

However, if I do this, doSomethingAfterSlideUp() will be executed myElements.length times.

Enter the promise() function. If I change this to look like so, I get the desired bahavior:

Leave a Reply

Your email address will not be published. Required fields are marked *


6 − = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">