I'm having a little group iterating over an array with Jquery. I have an array and I want each item in the array to fade in and out (and switch to the next while it's faded out). I can make it loop the appropraite amount of times, but the for loop always shows the last variable, not each one in order.
var x = [1,2,3,4,5];
$("#test").text("test");
var y = 0;
for(var i = 0; i<x.length;i++){
$("#test").delay(1000).animate({opacity:'0'},function(){
$(this).text(i)
}).delay(1000).animate({opacity:'1'});
}
So, the p tag this refers to starts off as "text", then flashed '5' five times instead of counting. I thought the delay would work, but the for loop finishes and doesn't wait for the jquery to complete.