Fork me on GitHub

The Problem:

When you iterate over jQuery objects using $('img').each(); your callback function runs instantly on each element, but what if you wanted to apply .addClass() on each element in order rather than simultaneously?

Example:


The Solution:

Place the callback functions inside window.setTimeout() window.requestTimeout() and set the timeout duration * i where i is the step number.

Example:

Which is exactly what jQuery.eachStep is doing behind the scenes!


∞ jQuery.eachStep created by Derek Anderson // Media Upstream ∞ Placeholder kittens thanks to {placekitten}