Answer the question
In order to leave comments, you need to log in
Why is the class not being added?
Hello
My code - Fiddle
Using carouselbootstrap 3
$('.carousel-indicators li').click(function(e) {
e.stopPropagation();
$('.carousel').carousel($(this).data('slide-to') - 1);
});
// change the indicator background on click
$('.carousel-indicators li').on("click", function() {
$('.carousel-indicators li.active').removeClass("active");
$(this).addClass("active");
});
$('.carousel').bind('slid', function() {
$('.carousel-indicators .active').removeClass('active');
var activeIndex = $('.carousel .item.active').index();
$('.carousel-indicators li:eq(' + activeIndex + ')').addClass('active');
});
.active
to acc. slide Answer the question
In order to leave comments, you need to log in
If I'm not mistaken, then you have $(this) points to the click event, and not to the element that was clicked, try this:
$('.carousel-indicators li').each(function(){
var li=$(this);
li.on("click", function () {
$('.carousel-indicators li.active').removeClass("active");
li.addClass("active");
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question