In the for
loop i'm iterating through the array of strings and meanwhile changing the src
of image but, setTimeout
method is not holding myfun
for 3000 ms because of this the for loop just iterate in a blink of any eye to the last string of array. Where I'm going wrong?
<script>
function myfunction(){
var arr = ["mind.jpg","images.jpg","external.jpg"];
var image = document.getElementById("IMAGE");
for(var i =0;i<arr.length;i++)
{
setTimeout(myfun,3000);
image.src = arr[i];
}
}
function myfun(){
}
</script>