How To Trigger Bootstrap Carousel's Carousel-indicators
What's wrong with my code? I want to trigger the current bootstrap carousel slide number. I want to change a text or do some jQuery command when a specific slide. Please see my cod
Solution 1:
Try
$(document).ready(function() {
$('#myCarousel').on('slide.bs.carousel', function (ev) {
var idx = $(ev.relatedTarget).index() + 1;
console.log(idx);
});
})
Solution 2:
Thanks to tmg for his code, heres the correct html code for those who are looking for the ready code.
$(document).ready(function() {
$('#myCarousel').on('slide.bs.carousel', function (ev) {
var idx = $(ev.relatedTarget).index() + 1;
/* console.log(idx);*/
idx = parseInt(idx);
switch (idx) {
case1:
$('#sometext').text("one");
break;
case2:
$('#sometext').text("two");
break;
case3:
$('#sometext').text("three");
default:
//the id is none of the above
$('#sometext').text("default");
}
});
});
Post a Comment for "How To Trigger Bootstrap Carousel's Carousel-indicators"