0

Guys I don't know how to add some interval of time in javascript. Do you know how to add some time before changing src of an image. i get this code from W3schools

document.getElementById("image").src = "http://www.w3schools.com/js/landscape.jpg";
<!DOCTYPE html>
<html>
<body>

<img id="image" src="http://www.w3schools.com/js/smiley.gif" width="160" height="120">

<p>The original image was smiley.gif, but the script changed it to landscape.jpg</p>

</body>
</html>

JsFiddle

qasim ali
  • 37
  • 2
  • 10

1 Answers1

4

setTimeout(function() {
                      document.getElementById("image").setAttribute("src", "http://www.w3schools.com/js/landscape.jpg");
                  }, 5000);
<img id="image" src="http://www.w3schools.com/js/smiley.gif" width="160" height="120">

<p>The original image was smiley.gif, but the script changed it to landscape.jpg</p>

I have updated your fiddle

Keerthi
  • 923
  • 6
  • 22