Skip to content

Instantly share code, notes, and snippets.

@jaredhabeck
Last active December 14, 2015 16:08
Show Gist options
  • Save jaredhabeck/5112683 to your computer and use it in GitHub Desktop.
Save jaredhabeck/5112683 to your computer and use it in GitHub Desktop.
// Make sure you have a parent element that wraps the checkboxes you want to check has an ID set
// in this case it's "interest" - so <fieldset id="interest">.
$('#checkall').click(function(e) {
e.preventDefault();
$('#interest').find('input[type="checkbox"]').each(function(item) {
if ($(this).attr('checked')) {
$(this).attr('checked', false);
} else {
$(this).attr('checked', true);
}
var target = $(this).next('label').attr('for');
if (document.getElementById(target)) {
populateField(target);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment