Reputation:
I have written html as
<select class="ddl">
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value="3">Cherry</option>
</select>
Now I want that if option is 1 then it should be selected as
<option value="1" selected="selected">Apple</option>
Please help me !!!
Upvotes: 0
Views: 1700
Reputation: 3571
For versions 1.6
and higher
you can use,
$('.ddl option:eq(1)').prop('selected', true);
For older
versions you can use,
$('.ddl option:eq(1)').attr('selected', 'selected');
Upvotes: 0
Reputation: 337560
You can use the val()
method to set the selected option in a select
, much as you would use it to set the value
attribute of a standard input
element. Try this:
$('select.ddl').val('1');
Upvotes: 3