Checkbox "check all" ever with jQuery

<fieldset>
// these will be affected by check all
<div>
<input type="checkbox" class="checkall"> Check all</div>
<div>
<input type="checkbox"> Checkbox</div>
<div>
<input type="checkbox"> Checkbox</div>
<div>
<input type="checkbox"> Checkbox</div>
</fieldset>
<fieldset>
// these won't be affected by check all; different fieldset
<div>
<input type="checkbox"> Checkbox</div>
<div>
<input type="checkbox"> Checkbox</div>
<div>
<input type="checkbox"> Checkbox</div>
</fieldset>

And using function

$(function () { // this line makes sure this code runs on page load
$('.checkall').click(function () {
$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
});
});

0 comments:

Đăng nhận xét

Có nhận xét mới

Like