Reputation: 8331
I am trying to add a class to the label of radio button. The class that is added varys depending on whether the button is selected or not. How do I test for a not checked status?
if (ui.item.Status) {
$('input:radio[name="StatusType.Active"]')[0].checked = true;
} else {
$('input:radio[name="StatusType.Active"]')[1].checked = true;
}
$('input:radio[name="StatusType.Active"]:checked').parent().addClass('btn-success');
$('input:radio[name="StatusType.Active"]:!checked').parent().addClass('btn-failure');
Upvotes: 1
Views: 969
Reputation: 59232
You can do this instead by using function callback of addClass
var elem = $(':radio[name="StatusType.Active"]');
elem.parent().addClass(function(){
return "btn-" + (elem.is(":checked") ? "success" : "failure");
});
Upvotes: 7
Reputation: 115222
Use not()
method in jQuery
$('input:radio[name="StatusType.Active"]').not(':checked').parent().addClass('btn-failure');
Upvotes: 1
Reputation: 11731
something like :not
:-
$('input:radio[name="StatusType.Active"]:not(:checked)').parent().addClass('btn-failure');
Upvotes: 0