I have a problem in carousel class in bootstrap. I have defined a button which is by default a pause button, then i use a javascript function on that button to control the carousel like when clicked, the icon should change to play and the carousel should stop the cycle, but .click(function) is not working when the button is clicked instead it is pausing the carousel when i position the mouse on the button. please help me solve this problem.
$(document).ready(function(){ $("#mycarousel").carousel( { interval: 2000 } ); $("#carouselButton").click(function() { if ($("#carouselButton").children("span").hasClass('fa-pause')) { $("#mycarousel").carousel("pause"); $("#carouselButton").children("span").removeClass('fa-pause'); $("#carouselButton").children("span").addClass('fa-play'); } else if ($("#carouselButton").children("span").hasClass('fa-play')) { $("#mycarousel").carousel("cycle"); $("#carouselButton").children("span").removeClass('fa-play'); $("#carouselButton").children("span").addClass('fa-pause'); } }); });