Skip to content

Instantly share code, notes, and snippets.

@awkale
Created April 21, 2014 18:59
Show Gist options
  • Save awkale/11152769 to your computer and use it in GitHub Desktop.
Save awkale/11152769 to your computer and use it in GitHub Desktop.
checkbox select all
$(function () {
$('.checkall').on('click', function () {
$(this).closest('fieldset').find(':checkbox').prop('checked', this.checked);
});
});
<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 field set -->
<div><input type="checkbox"> Checkbox</div>
<div><input type="checkbox"> Checkbox</div>
<div><input type="checkbox"> Checkbox</div>
</fieldset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment