1

I've a "stupid" problem: when I click a specific button, I want to reset the checkbox checked in unchecked.

HTML

<input type="checkbox">1
<input type="checkbox">2
<button id="clear">Clear</button>

JS

jQuery("#resetta").click(function(){
jQuery('input:checked').removeAttr('checked');
});
Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187

4 Answers4

4

The provided answers are correct for checkboxes, but if you intend to make a complete form with other inputs, something like the input type reset may be easier, this is a button to reset the form:

<input type="reset" value="Reset">
Jimmy Knoot
  • 2,338
  • 19
  • 29
2

You can use .prop('checked',false); for that

jQuery('input:checked').prop('checked',false);

Fiddle

Anoop Joshi P
  • 24,863
  • 8
  • 29
  • 52
2

You need to use .prop() to set the checked property instead of removing the attribute

jQuery('input:checked').prop('checked', false);
Community
  • 1
  • 1
Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
0

You can use removeProp() instead of removeAttr()

jQuery('input:checked').removeProp('checked');

Please check this for prop vs attr

Community
  • 1
  • 1
Bhushan Kawadkar
  • 27,908
  • 5
  • 34
  • 57