Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the text of the selected option of a select using jquery?

If I have this select:

     <select id="days">
        <option value="0">Today</option>
        <option value="1">Yesterday</option>
        <option value="7">Last week</option>
     </select>

and someone selects the 3rd option 'last week', I can get the value of last week (which is 7), using $("#days").val(), but how can I get the value of the text i.e 'Last week'?

like image 681
Ali Avatar asked Sep 07 '09 21:09

Ali


People also ask

How do I get a dropdown selected value and text?

We can select text or we can also find the position of a text in a drop down list using option:selected attribute or by using val() method in jQuery. By using val() method : The val() method is an inbuilt method in jQuery which is used to return or set the value of attributes for the selected elements.


1 Answers

$("#days option:selected").text()
like image 124
manji Avatar answered Oct 18 '22 16:10

manji