images are
- sf.jpg
- sf2.jpg
sf3.jpg
Change above img src in each 5 sec in first 5 sec image should be sf.jpg in second 5 sec image should be sf2.jpg in third 5 sec image should be sf3.jpg
and it should work repeatdly forever
images are
sf3.jpg
Change above img src in each 5 sec in first 5 sec image should be sf.jpg in second 5 sec image should be sf2.jpg in third 5 sec image should be sf3.jpg
and it should work repeatdly forever
Check this below code snippet.
I have altered alt attribute after 2 secs. In your code replace alt to src.
$(window).on('load', function() {
let src = ['image_1.jpg', 'image_2.jpg', 'image_3.jpg', 'image_4.jpg'];
let i = 1;
setInterval(function() {
$('img').prop('alt', src[i]);
if (i !== src.length)
i++;
else
i = 0;
}, 2000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src='image_1.jpg' alt='image_1.jpg' width='200' height='200' />
Hope, it works for you. :) :)