First of all check if the checkbox is already checked or not.
jQuery('#my-checkbox').is(':checked');
If it is not checked then do it checked.
jQuery('#my-checkbox').attr('checked','checked');
And if it is already checked then make it unchecked.
jQuery('#my-checkbox').removeAttr('checked');
And if you to check/uncheck all checkboxes.
// Check anything that is not already checked:
jQuery(':checkbox:not(:checked)').attr('checked', 'checked');
// Remove the checkbox
jQuery(':checkbox:checked').removeAttr('checked');
That's it .
0 Comment(s)