I am attempting to implement JavaScript to update the checkbox siblings in it's corresponding div. I have multiple div's that have the same checkbox options: #check_all_checkboxes, #check_none, and .others. I want the div to update their siblings, but the JavaScript will not update the siblings. I can hardcode the sibling class or id and the JavaScript will successfully execute on the first div, but not on the successive div's.
// Select ALL checkboxes
$('#check_all_checkboxes').click(function () {
if ( $(this).is(':checked') ){
$(this).siblings('.others').prop('checked', true);
$(this).siblings('#check_none').removeAttr('checked');
}
});
// Select NO checkbox(es)
$('#check_none').click(function () {
if ( $(this).is(':checked') ){
$(this).siblings('.others').removeAttr('checked');
$(this).siblings('#check_all_checkboxes').removeAttr('checked');
}
});
// Select other checkbox(es)
$('.others').click(function () {
$(this).siblings('#check_none').removeAttr('checked');
$(this).siblings('#check_all_checkboxes').removeAttr('checked');
});