The error is Uncaught TypeError: Cannot read properties of undefined (reading 'style')
Code:
let slideIndex = 0;
showSlides();
function showSlides() {
let i;
let slides = document.getElementsByClassName("mySlides");
let 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"; //Error is showed at this line
dots[slideIndex-1].className = " active";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
I included my script tag in index.html of public folder Rest javascript files are working except this
CodePudding user response:
const mystyle = { display: "block", };
CodePudding user response:
const mystyle = { display: "block", };
const mystyle = {
display: "block",
};
<div className="Works" style={slideIndex == 0 ? mystyle : null}></div>