-7

images are

  1. sf.jpg
  2. sf2.jpg
  3. 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

  • Possible duplicate of [Changing the image source using jQuery](https://stackoverflow.com/questions/554273/changing-the-image-source-using-jquery) – Nisarg Shah Aug 20 '17 at 06:10
  • Please read the help page how to ask a question. – michelem Aug 20 '17 at 06:10
  • I have linked an answer as duplicate, that shows how you could change the `src` attribute on an image. Combined with [`setInterval`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval) you can change implement your requirement. – Nisarg Shah Aug 20 '17 at 06:11

1 Answers1

0

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. :) :)

Chaitanya Ghule
  • 451
  • 1
  • 5
  • 11