I have a very simple requirement for my jQuery: check the set of mailboxes if the switch is set, and clear them if another checkbox is selected.
Jquery works, however it only works once - that is, if I click to check them all (all checkboxes are checked), then click to clear them (all boxes are cleared), and then click again to check them all - there is no effect. Similarly, if I manually uncheck some boxes, then click to select all again, there is no effect.
JQuery
$('#all').on('change', function() { if (!$(this).is(':checked')) { $('.country').attr('checked', false); } else { $('.country').attr('checked', true); } }); $('#none').on('change', function() { if (!$(this).is(':checked')) { $('.country').attr('checked', true); } else { $('.country').attr('checked', false); } });
HTML
<div class="subselect"> <input type="radio" class="TLO" name="radio1" id="all" />Check All <br /> <input type="radio" class="TLO" name="radio1" id="none" />Clear All <br /> </div> <br /> <br /> <div class="cselect" id="countries"> <input type="checkbox" class="country" />1 <br /> <input type="checkbox" class="country" />2 <br /> <input type="checkbox" class="country" />3 </div>
jsFiddle http://jsfiddle.net/vsGtF/1/
Gideon
source share