Looking to add some flair to my Bootstrap buttons by changing their color when clicked. The goal is for the button to go from gray (btn-default) to green (btn-success) with each click, and then back to its default state on the next click. I attempted to achieve this with an if statement, but it seems to change color only once and doesn't revert to the original class upon subsequent clicks.
$("#critical_btn").click(function () {
if (this.class= 'btn-default'){
$('#critical_btn').removeClass('btn-default').addClass('btn-success ');
$(this).addClass('btn-success').removeClass('btn-default');
}
else if (this.class= 'btn-success'){
$('#critical_btn').removeClass('btn-success').addClass('btn-default ');
$(this).addClass('btn-default').removeClass('btn-success');
}
});
I'm still getting the hang of this, so any advice or pointers would be tremendously helpful!