I'm trying to select multiple checkboxes inside a div, if a specific checkbox is selected. Here's what I'm trying to do http://jsfiddle.net/8PLH6/
I'm trying to make this work. If I check "All" all the below checkboxes should be selected. For some reason I can't get the selectors right. Code:
<div style="float:left;padding-right:15px;">
<div align="left" style="padding-bottom: 4px; padding-left: 6px;" class="bottom">
<input type="checkbox" value="1" id="all"/><a href="#" title="All">All</a>
</div>
<div align="left" style="padding-bottom: 4px; padding-left: 6px;" class="bottom">
<input type="checkbox" value="1" id="cat417"/><a href="" title="1">1</a>
</div>
<div align="left" style="padding-bottom: 4px; padding-left: 6px;" class="bottom">
<input type="checkbox" value="1" id="cat410"/><a href="" title="2">2</a>
</div>
<div align="left" style="padding-bottom: 4px; padding-left: 6px;" class="bottom">
<input type="checkbox" value="1" id="cat401"/><a href="" title="3">3</a>
</div>
<div align="left" style="padding-bottom: 4px; padding-left: 6px;" class="bottom">
<input type="checkbox" value="1" id="cat415"/><a href="" title="4">4</a>
</div>
</div>
and
$(document).ready(function () {
$('#all').change(function () {
$a = $(this).parent('div').parent('div').children('div').children('input[type="checkbox"]');
$b = $(this).attr('checked');
if ($b) {
$($a).attr('checked', true);
} else {
$($a).attr('checked', false);
}
});
});