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.
You’d use
prop:If you’re in a version of jQuery pre 1.6, you’d use:
Don’t use
attrorremoveAttrfor changing:checkedstate!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.Here’s an example