I have the following jQuery code which is suppose to switch between classes on click. The code works on the first click but once I click on the same element for the second time it never switches to the opposite class. What am I doing wrong?
// enable on click
$('.disabled').click(function(event)
{
$(this).removeClass("disabled").addClass("enabled");
$(this).html("enabled");
});
// disable on click
$('.enabled').click(function(event)
{
$(this).removeClass("enabled").addClass("disabled");
$(this).html("disabled");
});
You have to use the
livemethod if you want to define events for future elements. Thebindmethod only attaches events to the current elements which match the selectorAn alternative method: