+ 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 }
1 Odpowiedź
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
}