A question. Why can't I write style.block to slides?
var slideIndex = 1; showSlides(slideIndex); function plusSlides(n){ showSlides(slideIndex += n); } function currentSlide(n){ showSlides(slideIndex = n); } function showSlides(n){ var i; var slides = document.getElementsByClassName("mySlides"); var dot = document.getElementsByClassName("dot"); if(n > slides.length){ slideIndex = 1; } if(n < 1){ slideIndex = slides.length; } for(i=0; i <slides.length; i++){ slides[i].style.display = "none"; } for(i = 0; i < dot.length; i++){ dot[i].className = dot[i].className.replace("active", ""); } slides[slideIndex-1].style.display = 'block'; dot[slideIndex-1].className += "active"; }
dot, and withslides, hang a new class on the object, something likeslideShow/slideHide, which will be described in css with thedisplay:block; / display:noneruledisplay:block; / display:nonedisplay:block; / display:none. Well, the reason why it does not work. it may be that 1) the slides object can be empty (length = 0) 2) slideIndex can go beyond the array. - alexoander