Using the val() we can get the value associated to an element.
In some cases we may need to get text associated to that element; for example in a dropdown we may need to get the text for displaying on Screen.
So lets see How to get Text of Dropdown Selected Option in jQuery.
How to get Text of Dropdown Selected Option in jQuery
We have a dropdown with States and their codes.
1 2 3 4 5 6 |
<select id="statesDropDown"> <option value="AL">Alabama </option> <option value="CA">California</option> <option value="FL">Florida</option> <option value="TX">Texas</option> </select> |
Now to get the text of the selected option we use the following syntax
1 |
$( "#ELEMENT_ID option:selected" ).text(); |
In our case it will be
1 |
$( "#statesDropDown option:selected" ).text(); |
So if 3rd Option is selected we will get the text as “Florida”.