Just copy this function.
function InitCheckAll(checkAllSelector, checkboxSelector) { $(checkAllSelector).change(function() { var e = this; $(checkboxSelector).each(function() { this.checked = e.checked; }); }); $(checkboxSelector).change(function() { if (this.checked == true) { var isCheckAll = true; $(checkboxSelector).each(function() { if(!this.checked) { return isCheckAll = false; } }); $(checkAllSelector)[0].checked = isCheckAll; } else { if ($(checkAllSelector)[0].checked == true) { $(checkAllSelector)[0].checked = false; } } }); }Then you can declare select/deselect all checkbox just a line code. Notice that the paramaters should be selector string. For example:
InitCheckAll('#yourMasterCheckBoxID', '.yourChildCheckBoxClass')