Reputation: 476
So I have this JQuery that intends to uncheck a particular class of checkbox:
$('.boringassclassname_class').prop('checked', false);
And I have this checkbox as requested by someone who needed an MVE:
<input type="checkbox" id="whocares" name="doesntmatter" class="boringassclassname_class">
I fire this inside another checkbox's onchange, and it does nothing. The class of checkbox does not uncheck. No exceptions.
This is jquery 1.8.3, so I shouldn't need to use attr for this. I tried using
$('.boringassclassname_class').each(function() { ($this).prop('checked', false) })
but that threw errors that $this was undefined. The class selector most certainly is not undefined, since show() and hide() work just fine on it.
I tried researching mass selectors and doers, but nothing in my searches came up that allowed it to apply to a class. So how do I uncheck a class of checkbox?
Upvotes: 1
Views: 456
Reputation: 24965
You do not have to use an each. prop()
does an implicit iteration over the result stack.
$('.ARTReason_1_AbnormSpermParams_AzoospermiaObs_PriorVasectomy_class').prop('checked', false);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="whocares" name="doesntmatter" class="ARTReason_1_AbnormSpermParams_AzoospermiaObs_PriorVasectomy_class" checked>
<input type="checkbox" id="whocares" name="doesntmatter" class="ARTReason_1_AbnormSpermParams_AzoospermiaObs_PriorVasectomy_class" checked>
<input type="checkbox" id="whocares" name="doesntmatter" class="ARTReason_1_AbnormSpermParams_AzoospermiaObs_PriorVasectomy_class" checked>
Upvotes: 1
Reputation: 1794
write $(this) instead of ($this)
$('.{$id}_class').each(function() { $(this).prop('checked', false) })
Upvotes: 3