Advertisement
Advertisement


Keep option selected label in a select with jquery


Question

i would like to keep option selected label. I have the following select :

<select id="myselect">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>

So i have done the following code :

jQuery("#myselect").val();

But it return me 1, 2, or 3, in order to return me A,B, or C. Unfortunately i can't change my select and the attr 'value'.

Thanks for your help!!!

2013/09/14
1
0
9/14/2013 5:46:52 PM


Use this.

 alert(jQuery("#myselect option:selected").text());
2013/09/12

If you want each option text at a time then use

alert($("#myselect >option").text());

and If you want selected option text then use

alert($("#myselect >option: selected ").text());
2013/09/12

Try this:

jQuery("#myselect option:selected").text()
2013/09/12

Working Solution:

$("#your_select_id option:selected").attr('label');
2015/01/07