tags:

views:

36

answers:

2
<select id="name">
 <option value="1005">peter</option>
 <option value="2056" selected="selected">shan</option>
</select>

how to set option's text=peter selected?
like this $('#name option[text=peter]').attr('selected',true);

+1  A: 
 $("#name option[value='1005']").attr('selected','selected');
Chinmayee
your answer is not work.
BRAVO
@BRAVO, I'd suggest using `...attr('selected', true);` rather than `'selected','selected'` but this **does** (or **should**) work. [Demo at: JS Fiddle](http://jsfiddle.net/davidThomas/Chtdk/).
David Thomas
A: 

also

$("#name option[text=peter]").attr("checked", "checked");

works.

Musa Hafalır
It should be $("#name option[text=peter]").attr("selected", "selected"); as it is a select box other option is $("#name option:contains('peter')").attr('selected', 'selected');
Chinmayee
you are right actually but ("checked", "checked") also works.
Musa Hafalır