Set select option 'selected', by value
11:46
I
have a select field with some options in it. Now I need to select one of those
options with jQuery. But how can I do that when I only know the value of the
option that must be selected?
I
have the following HTML:
<div class="id_100">
<select>
<option value="val1">Val 1</option>
<option value="val2">Val 2</option>
<option value="val3">Val 3</option>
</select>
</div>
I need to select the option with
value val2. How can this be done?
==========================
Anwser:$("div.id_100 select").val("val2");
Check out the following jQuery method:
http://api.jquery.com/val/
Another answer:
To select an option with value 'val2':
$('.id_100 option[value=val2]').attr('selected','selected');
0 nhận xét