I'm trying to show next slide on Next Button Click with the following code, but when I click the Next button the currentSlide
function is not working. I have even made the functions global but still it's not working
The code which isn't working is the below, in console i can see the message ok
and index
value is also fine but the currentSlide function isn't working:
// When next is clicked
$('.next-slide').click(function() {
var index = $(this).attr('data-index')
currentSlide(index);
console.log('ok');
});
Full Code
$(document).ready(function(){
// The below code is for evaluation quiz slider
var slideIndex = 1;
window.plusSlides = function(n) {
showSlides(slideIndex += n);
}
window.currentSlide = function(n) {
$('.next-slide').attr('data-index', n);
showSlides(slideIndex = n);
}
window.showSlides = function(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = 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 < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "inline";
dots[slideIndex-1].className += " active";
}
showSlides(slideIndex);
// When next is clicked
$('.next-slide').click(function() {
var index = $(this).attr('data-index')
currentSlide(index);
console.log('ok');
});
});