I have created a carousel for which I have included a play/pause button. I am using bootstrap and have added the following code.
<button class="btn btn-danger btn-small" id="carousel-button">
<span class="fa fa-pause"></span>
</button>
Jquery:
$(document).ready(function() {
$("#carousel-button").click(function() {
if ($("#carousel-button").children("span").hasClass('fa-pause')) {
$("#mycarousel").carousel('pause');
$("#carousel-button").children("span").removeClass('fa-pause');
$("#carousel-button").children("span").addClass('fa-play');
} else if ($("#carousel-button").children("span").hasClass('fa-play')) {
$("#mycarousel").carousel('cycle');
$("#carousel-button").children("span").removeClass('fa-play');
$("#carousel-button").children("span").addClass('fa-pause');
}
});
});
I do not understand where it is getting wrong and why the button won't change after clicked.