How to reset all checkboxes using jQuery or pure JS?
If you mean how to remove the 'checked' state from all checkboxes:
$('input:checkbox').removeAttr('checked');
I have used this before:
$('input[type=checkbox]').prop('checked', false);
seems that .attr and .removeAttr doesn't work for some situations.
edit: Note that in jQuery v1.6 and higher, you should be using .prop('checked', false)
instead for greater cross-browser compatibility - see https://api.jquery.com/prop
Comment here: How to reset all checkboxes using jQuery or pure JS?
If you want to use form's reset feature, you'd better to use this:
$('input[type=checkbox]').prop('checked',true);
OR
$('input[type=checkbox]').prop('checked',false);
Looks like removeAttr()
can not be reset by form.reset()
.
The above answer did not work for me -
The following worked
$('input[type=checkbox]').each(function()
{
this.checked = false;
});
This makes sure all the checkboxes are unchecked.