I'm currently utilizing a script from the WOW Slider (free version) that looks like this:
var slideIndex = 0;
function showSlides() {
var i;
slides = document.getElementsByClassName("mySlides");
dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {slideIndex = 1}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
setTimeout(showSlides, 3000); // Change image every 2 seconds
}
showSlides();
Everything appears to be functioning fine, but during an SEO check on the page, an error in the following line of Javascript was flagged:
slides[slideIndex-1].style.display = "block";
The specific error message is as follows:
"Uncaught TypeError: Cannot read property 'style' of undefined".
This error suggests that slides
is not defined, even though it is initialized in the variable declarations.
I'm relatively new to Javascript and would greatly appreciate any assistance with resolving this issue. Thank you in advance.