0

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);

2 Answers 2

2
$('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">

Sign up to request clarification or add additional context in comments.

1 Comment

I'd usually suggest text to explain an answer, but it's so incredibly basic I don't think it warrants wone..
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.