I have this code:
HTML
<table class=tbl>
<tr>
<td>
<input class='c1' type='checkbox'>
<label>Ceckbox1</label>
</td>
<td>
<input class='c2' type='checkbox'>
<label>Ceckbox2</label>
</td>
<td>
<input class='c2' type='checkbox'>
<label>Ceckbox2</label>
</td>
<td>
<input class='c2' type='checkbox'>
<label>Ceckbox2</label>
</td>
</tr>
</table>
<table class=tbl>
<tr>
<td>
<input class='c1' type='checkbox'>
<label>Ceckbox1</label>
</td>
<td>
<input class='c2' type='checkbox'>
<label>Ceckbox2</label>
</td>
<td>
<input class='c2' type='checkbox'>
<label>Ceckbox2</label>
</td>
<td>
<input class='c2' type='checkbox'>
<label>Ceckbox2</label>
</td>
</tr>
</table>
JavaScript
$('.c2').click(function () {
if ($(this).parent().find('.c2').is(':checked')) {
alert('all are checked');
} else {
alert('none are checked');
}
});
I am trying, with no result, to use jquery to auto-check ‘c1’ only when all the ‘c2’ from the same ‘tbl’ are checked. The count of ‘c2’ can vary as can the count of ‘tbl’.
Try this code it works:
DEMO