hello,
i am actually trying to learn carousel with html css js and i have a doubt in this code i.e
code for automatice slideshow
var slideIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
var dots=document.getElementsByClassName("dot");
for(i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if(slideIndex > x.length) {slideIndex = 1}
for(i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
x[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
setTimeout(carousel, 8000);
}
// here my slideshow is working but i am getting here 1 error that is
code2.js:31 Uncaught TypeError: Cannot read property ‘style’ of undefined
at showDivs (code2.js:31)
at code2.js:2
showDivs @ code2.js:31
(anonymous) @ code2.js:2
this is my code for slider
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
var dots=document.getElementsByClassName("demo");
if(n > x.length) {slideIndex = 1}
if(n < 1) {slideIndex = x.length}
for(i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for(i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
x[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
I AM GETTING THE AUTOMATIC SLIDESHOW AND SLIDER BUT IT IS SHOWN IN THE CONSOLE THAT I HAVE 1 ERROR PLEASE TELL ME WHERE AM I WRONG
THANK YOU