i have an array of 3 items. i want to display each item with a delay in between and remove the previous one. my code works for displaying each item but i can't remove the previous one. if i add html('') at the end of each loop.. it'll remove everything before the item gets display due to the delay. here is jsfiddle https://jsfiddle.net/qawzzzjz/
<div class='view'>
</div>
var arr = ['First', 'Second', 'Third'];
for(var i=1; i<arr.length+1; i++){
$("<h3 style='display: none;'>"+arr[i-1]+"</h3>").appendTo('.view').delay(1000*i).fadeIn(500);
}
I also tried this code but it only shows the third item
var arr = ['First', 'Second', 'Third'];
for(var i=1; i<arr.length+1; i++){
$('.view').html("<h3>"+arr[i-1]+"</h3>").delay(1000*i);;
}