Having an issue with a button that needs to change its function after meeting a certain condition.
I am attempting to select the button by its class, remove that class when the condition is met, add a new class, and then perform another action. However, it is not working as expected.
Here is an example of my problem:
$('.button-1').click(function(){
$('.box').width(function(){
return $(this).width() + 10;
});
$(this).removeClass('button-1').addClass('button-2');
});
$('.button-2').click(function(){
$('.box').width(function(){
return $(this).width() - 10;
});
$(this).removeClass('button-2').addClass('button-1');
});
You can view the code on this Fiddle link.
My expectation was for the black box width to toggle between increasing and decreasing, but it continues to increase only.