First view to the question inspired to suggest event.preventDefault()
because of "preventing checkboxes from being checked ..". Bu later reading it again and again i understand that you want something different. "Checking and hiding" steps ahead. I prepared a demo at jsFiddle for this question.
'upper checkboxes' control the 'sub checkboxes' with:
$("input.upper-box").on("change", function() {
var $this = $(this);
$this.next("div.sub-group")
.find(":checkbox")
.prop("checked", $this.prop("checked"))
.end()
.toggle("slow");
});
One little note about checkboxes that jquery team suggests is that you should use prop()
instead of attr()
if you target ($ 1.6+).