
I just created a MVC 4 application in which I have a table with many rows. Each row has an Active or an Inactive status.
If the record is in an active state it's showing this buttons (like as in the 2nd row in the picture above).
<button
class="btn btn-xs active btn-primary"
data-HEI_ID = @item.HEI_ID
data-status = "true">Active
</button>
<button
class="btn btn-xs inactiveColor btn-default"
data-HEI_ID = @item.HEI_ID
data-status = "false">Inactive
</button>
If it's in inactive state it's showing this buttons (like as in the 1st row in picture above):
<button
class="btn btn-xs btn-default"
data-HEI_ID = @item.HEI_ID
data-status = "true">Active
</button>
<button
class="btn btn-xs inactiveColor btn-primary active"
data-HEI_ID = @item.HEI_ID
data-status = "false">Inactive
</button>
Here is the jQuery function:
$('.btn-toggle').click(function () {
$(this).find('.btn').toggleClass('active');
if ($(this).find('.btn-primary').size() > 0) {
$(this).find('.btn').toggleClass('btn-primary');
}
if ($(this).find('.btn-danger').size() > 0) {
$(this).find('.btn').toggleClass('btn-danger');
}
if ($(this).find('.btn-success').size() > 0) {
$(this).find('.btn').toggleClass('btn-success');
}
if ($(this).find('.btn-info').size() > 0) {
$(this).find('.btn').toggleClass('btn-info');
}
$(this).find('.btn').toggleClass('btn-default'); {
}
});
But when I click the selected state, either active or inactive, it is switching the buttons.
How to prevent this using jQuery?