jQuery Perform action if checkbox "A" is the only one checked
Can you run a check to see if a checkbox is the only value checked against a group?
$("#ID").change(function() {
if ($("#checkboxA").is(":checked") && NOTHING ELSE开发者_StackOverflow中文版 IS CHECKED) {
//do somethinge
} else {
//do something else
}
});
I need help with the "&& NOTHING ELSE IS CHECKED" and Im still not sure this would be a change function
You could check that only one checkbox is checked and that checkbox has the id of the one you are looking for. Working Demo
$("#ID").change(function() {
var checked = $("input:checkbox:checked");
if (checked.length === 1 && checked[0].id === 'checkboxA') {
//do something
}
else {
//do something else
}
});
What about selecting all checked checkboxes with
$('input:checkbox:checked')
And then running a check to make sure the length of this list is equal to 1?
精彩评论