I have the following list:
<select id="id1">
<option value="">Firstone</option>
<option value="1">Secondone</option>
<option value="2">Thirdone</option>
</select>
I did the following to select “Secondone” from the list:
$("#id1").val("1").attr('selected', 'selected');
This didn’t seem to select it.
How can I select “Secondone” from the list?
To set the selected value of a list you just need to use the
val()function, no need to set the attribute for selected.Example:
jsFiddle
If you’re trying to literally get the element that is currently selected, you can do this: