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
  • 1,048,767
  • 296
  • 4,058
  • 3,343

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,378
  • 20
  • 29
2

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

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

Fiddle

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
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
  • 384,651
  • 66
  • 527
  • 531
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
  • 28,279
  • 5
  • 35
  • 57