Change image in sequence from list - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Change image in sequence from list

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <img src="logo.png" id="target"> 
      <script language="javascript">
var counter = 0;//w  w  w  .  j a  v a 2s . c o m
var images = ["logo.png", "222.jpg"];
function myFunction() {
  counter++;
  if (counter > 1) {
       counter = 0
  }
  target = document.getElementById("target").src = images[counter];
}
function my2(){
  setInterval("myFunction()", 1000);
}
window.onload = function(){
my2();
}

      </script>  
   </body>
</html>

Related Tutorials