Powered by Blogger.

Select and Unselect All Checkboxes with jQuery


Select and Unselect All Checkboxes with jQuery

 Check if all checkboxes are selected
$('.abc:checked').length == $('.abc').length
You could do it every time a new checkbox is checked:
$(".abc").change(function(){if($('.abc:checked').length == $('.abc').length){//do something}};
If we want to check initailly if all check box are checked:

function check_all_add(){
if ($('.add:checked').length == $('.add').length) {
$(".add_all").attr("checked", 'checked');
}
else{
$(".add_all").attr("checked", '');
}
}
$(document).ready(function(){
check_all_add();
$(".add").change(function(){
check_all_add();
});

});

No comments