Reputation: 253
How do I target a specific input by its class name and value?
<input type="checkbox" class="something" value="1">
<input type="checkbox" class="something" value="2">
<input type="checkbox" class="something" value="3">
Target className something + value 2:
$('target classname = something, value = 2').prop('checked', true);
Upvotes: 0
Views: 260
Reputation: 131
To be specific include the type of the input which doesnt affect the other input types.
$('input[type=checkbox][class=something][value=2]').prop('checked',true);
If the value is dynamic then use .val() method and compare.
Upvotes: 1
Reputation: 11297
$('input[class=something][value=2]').prop('checked', true);
$('input[class=something][value=2]').prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" class="something" value="1">
<input type="checkbox" class="something" value="2">
<input type="checkbox" class="something" value="3">
Upvotes: 2