How to reset all checkboxes using jQuery or pure JS? How to reset all checkboxes using jQuery or pure JS? javascript javascript

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');


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().


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?