+ 1

Why was my style undefined and i got an execution on another platform or did i do something wrong?

var slideIndex = 0; showSlides(); function showSlides() {   var i;   var slides = document.getElementsByClassName("mySlides");   for (i = 0; i < slides.length; i++) {     slides[i].style.display = "none";   }   slideIndex++;   if (slideIndex > slides.length) {slideIndex = 1}   slides[slideIndex-1].style.display = "block";   setTimeout(showSlides, 2000); // Change image every 2 seconds }

9th Jun 2020, 7:11 PM
kolade Omotoyo
kolade Omotoyo - avatar
1 Answer
0
On sololearn js gets loaded before html ,so in that case elements don't exit yet ,and so you get an undefined error Put your js script inside this function to prevent it window.onload=function(){ Js script goes here }
9th Jun 2020, 7:28 PM
Abhay
Abhay - avatar