html - JavaScript won't change image - Slider -


i don't understand why slider won't work.

on html page, have first time, slider, , link javascript. in javascript, have array includes 2 images. unfortunately, slider doesn't work. image won't change. stays on first one.

what might wrong?

var myimage=document.getelementbyid("slide");    var imagearray=["image1.jpg", "image2.jpg"];    var imageindex=0;    function changeimage () {      slider.setattribute("src", imagearray [imageindex]);      imageindex++;      if (imageindex>=imagearray.length) {          imageindex=0;      }  }  var intervalhandle = setinterval(changeimage,2000);
<!doctype html>  <html lang="cs">    <head></head>    <body>           <img src="image1.jpg" id="slide"/>                   <script src="javascript.js"></script>      </body>  </html>

try following code:

var myimage=document.getelementbyid("slide");  var imagearray=["image1.jpg", "image2.jpg"];  var imageindex=0;  function changeimage () {     myimage.setattribute("src", imagearray [imageindex]);     imageindex++;     if (imageindex>=imagearray.length) {         imageindex=0;     } } setinterval(changeimage,2000); 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -