Reputation: 51937
I have this HTML:
<div id="SomeID">
<input type="checkbox" class="SomeClass">
<input type="checkbox" class="SomeClass">
<input type="checkbox" class="SomeClass">
</div>
I want to unselect all the checkboxes that are of type SomeClass.
$('#SomeID .SomeClass').each(function () {
$(this)....
});
How do I do that?
Thanks.
Upvotes: 1
Views: 725
Reputation: 179046
You'd use prop
:
$('#SomeID .SomeClass').prop('checked', false);
If you're in a version of jQuery pre 1.6, you'd use:
$('#SomeID .SomeClass').each(function () {
this.checked = false;
});
attr
or removeAttr
for changing :checked
state!There is a difference between changing the checked property on the element and changing the checked attribute, it's subtle, but worth mentioning.
If you change the attribute value, and the user resets the form, the "reset" state will be pulled from whether the [checked]
attribute exists. If you've been adding/removing the [checked]
attribute, you will have lost the original state of the checkbox.
Upvotes: 10