I can not understand the cause of the error:
cannot set property 'classname' of undefined.
What makes it happen in this example?
var slides = document.querySelectorAll('.sliderPage__slides .sliderPage__slide'); var currentSlide = 0; var slideInterval = setInterval(nextSlide, 2000); function nextSlide() { slides[currentSlide].className = 'sliderPage__slide'; currentSlide = (currentSlide + 1) % slides.length; slides[currentSlide].className = 'sliderPage__slide sliderPage__showing'; } .sliderPage { width: 100%; height: 90vh } .sliderPage__slides { position: relative; height: 300px; padding: 0px; margin: 0px; list-style-type: none } .sliderPage__slide { position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; opacity: 0; z-index: 1; transition: opacity 1s; font-size: 40px; padding: 40px; box-sizing: border-box; background: #333; color: #fff } .sliderPage__showing { opacity: 1; z-index: 2 } .sliderPage__slide:nth-of-type(1) { background: red } .sliderPage__slide:nth-of-type(2) { background: green } .sliderPage__slide:nth-of-type(3) { background: blue } .sliderPage__slide:nth-of-type(4) { background: purple } .sliderPage__slide:nth-of-type(5) { background: orange } .sliderPage__slide:nth-of-type(6) { background: gold } <div class="sliderPage__slider"> <ul class="sliderPage__slides"> <li class="sliderPage__slide sliderPage__showing">1</li> <li class="sliderPage__slide">2</li> <li class="sliderPage__slide">3</li> <li class="sliderPage__slide">4</li> <li class="sliderPage__slide">5</li> </ul> </div>