I have some checkboxes grouped using the attribute rel. When anyone is unchecked, I want to check if all are also unchecked, then do something.
Scenario: I have a parent checkbox that is all of the children are unchecked, the parent should be. If one or more is checked, the parent needs to be checked.
All child checkboxes have the class name child.
$('.child').change(function () {
var groupdId = $(this).attr('rel');
if($('.child').where('rel', groupId).any('checked', true)) <-- how do I do this?
{
//Uncheck the parent
}
else {
//Check the parent.
}
});
What I attempted here is: for elements with class .child AND rel == groupdId, if any of them are checked, do x.
$('.child[rel="' + groupId + '"']:checked').length > 0[rel=...]is a way to select against an attributehttp://api.jquery.com/attribute-equals-selector/
:checkedis a jQuery psuedo-selectorhttp://api.jquery.com/checked-selector/