alenan2013
alenan2013

Reputation: 207

How to select multiple elements by id using jQuery

I have two radio buttons:

<p>
    <label for="input_1">Path to Excellent </label> 
    <input id="input_1" name="radio" type="radio" value="1" />
</p>
<p>
    <label for="input_2">Award of Excellence</label> 
    <input id="input_2" name="radio" type="radio" value="2" />
</p>

I would like to get val() from one of them using their ids: "input_1" or "input_2" by jQuery, something like this:

$('input[#input_1,#input_2]:checked').val();

My aim is to get val() from one of them that is checked, by id. How can I do this?

Upvotes: 0

Views: 135

Answers (1)

BrTkCa
BrTkCa

Reputation: 4783

You can check the starts of the id in this case:

$("input[id^='input_']:checked").val();

Upvotes: 8

Related Questions