I have the following list:
<div id="test">test</div>
<ul>
<li>foo</li>
<li>bar</li>
<li>sta</li>
<li>cko</li>
</ul>
and the following jQuery code:
$(document).ready(function() {
$('li').each(function(index) {
$('#test').text($(this).text());
$('#test').show("drop", { direction: "down" }, 500, function() {
$("#test").delay(1000).hide("puff", {}, 100);
});
});
});
Logically, this should change the contents of the div test
to foo
, apply the drop and puff effect, change contents to bar
, apply the effect, and so on. But when you run it, the entire .each loop finishes up before the effects are started, so the last element cko
shows up first and gets animated 4 times.
How can i make each item get the effect and then move on to the next one?