get selected text dropdown

How to Get Selected Text from Dropdown using jQuery

Almost every website or application employs dropdowns to allow users to select from a list of values. So you may need to get selected text from dropdown using JavaScript or jQuery. In this article, we will learn how to get selected text from dropdown using jQuery.


How to Get Selected Text from Dropdown using jQuery

Let us say you have the following dropdown.

<select name="myDropdown" id="myDropdown">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>

  <option value="audi">Audi</option>
</select>

One of the simplest ways to get selected text from dropdown.

$("#myDropdown option:selected").text();

Alternatively, you can also use the following.

$("#myDropdown :selected").text();

If the above commands do not work for you, you can also try the following.

$('#myDropdown').find('option:selected').text();

We have seen several ways of getting selected text from dropdown using jQuery. If you are using a recent version of jQuery, all the above commands should be supported in it. If you are using an older version of jQuery, only then you may find some of the above commands not working for you.

Also read:

How to Get Data-id Attribute in jQuery/JavaScript
How to Check if Image is Loaded Using JavaScript/jQuery
How to Fix Ambiguous Column Name in MySQL
How to List All Foreign Keys to Table in MySQL
How to Check if Row Exists in MySQL

Leave a Reply

Your email address will not be published. Required fields are marked *