Skip to content

Instantly share code, notes, and snippets.

@mkay
Created February 4, 2014 11:10
Show Gist options
  • Save mkay/8801777 to your computer and use it in GitHub Desktop.
Save mkay/8801777 to your computer and use it in GitHub Desktop.
toggle check-all checkboxes
$(function(){
$('#checkAll').live('change', function(){
var isChecked = !$('.checkbox').prop('checked');
if($(this).is(':checked')){
$('.checkbox').prop('checked', isChecked);
} else {
$('.checkbox').removeAttr('checked');
}
});
$('.checkbox:checked').length == $('.checkbox').length;
$('.checkbox').change(function(){
if ($('.checkbox:checked').length == $('.checkbox').length) {
$('#checkAll').prop('checked', true);
}
else{
$('#checkAll').prop('checked', false);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment