ipid
ipid

Reputation: 253

target input with classname and value

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

Answers (2)

Chaitanya
Chaitanya

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

Adam Azad
Adam Azad

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

Related Questions