I'm trying to make a div fade in/out that's within an each statement. The problem is that next item is called before the fade in/out is complete.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<div id='one'>one</div>
<div id='two'>two</div>
<div id='three'>three</div>
<script>
$.each([ "one", "two", "three"], function() {
console.log( 'start - ' + this );
animate( this );
console.log( 'end - ' + this );
});
function animate( id )
{
box = '#' + id;
$(box).fadeOut( 500, function( )
{
console.log('showing - ' + id);
$(box).fadeIn( 500 );
$(box).css('backgroundColor','white');
});
}
</script>
console shows -
start - one
end - one
start - two
end - two
start - three
end - three
showing - one
showing - two
showing - three
I would want something like -
start - one
showing - one
end - one
start - two
showing - two
end - two
start - three
showing - three
end - three
So how can I wait for each 'each' to be completely finished before moving on to the next value?