Get selected text from a drop-down list (select box) using jQuery

2,226,004

Solution 1

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

Solution 2

Try this:

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

For an ASP.NET dropdown you can use the following selector:

$("[id*='MyDropDownId'] :selected")

Solution 3

The answers posted here, for example,

$('#yourdropdownid option:selected').text();

didn't work for me, but this did:

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

It is possibly an older version of jQuery.

Solution 4

If you already have the dropdownlist available in a variable, this is what works for me:

$("option:selected", myVar).text()

The other answers on this question helped me, but ultimately the jQuery forum thread $(this + "option:selected").attr("rel") option selected is not working in IE helped the most.

Update: fixed the above link

Solution 5

This works for me

$("#dropdownid").change(function() {
    alert($(this).find("option:selected").text());
});

If the element created dynamically

$(document).on("change", "#dropdownid", function() {
    alert($(this).find("option:selected").text());
});
Share:
2,226,004
haddar
Author by

haddar

Updated on July 08, 2022

Comments

  • haddar
    haddar almost 2 years

    How can I get the selected text (not the selected value) from a drop-down list in jQuery?

    • ankush981
      ankush981 almost 9 years
      Just my two cents: An "ASP" drop-down is no special; it's just good old HTML. :-)
    • Dilip Kumar Yadav
      Dilip Kumar Yadav over 7 years
      One can refer this article: javascriptstutorial.com/blog/…
    • rogerdpack
      rogerdpack over 7 years
      for vanilla javascript way, see stackoverflow.com/a/5947/32453
    • Shahid Hussain Abbasi
      Shahid Hussain Abbasi over 5 years
      Just $(this).prop('selected', true); replaced .att to .prop it worked for all browsers
    • Ali NajafZadeh
      Ali NajafZadeh almost 3 years
      $("#yourdropdownid option:selected").text();
  • kingfleur
    kingfleur over 12 years
    Not exactly the answer to the question, but was useful for me. The question wants the selected text.
  • MHollis
    MHollis about 12 years
    I think this should be $("#yourdropdownid").children("option").filter(":selected").‌​text() since is() returns a boolean of whether the object matches the selector or not.
  • scubbo
    scubbo almost 12 years
    I second the comment about is() returning a boolen; alternatively, use the following small alteration: $('#yourdropdownid').children("option:selected").text();
  • Simon
    Simon about 11 years
    $('select').children(':selected') is the fastest way: jsperf.com/get-selected-option-text
  • Daniel Tonon
    Daniel Tonon about 4 years
    Thanks for providing a pure-JS approach.
  • Leffa
    Leffa about 2 years
    And if have scape caracteres like \n \t you can add .trim() getting like this: $("#yourdropdownid option:selected").text().trim();
  • Leffa
    Leffa about 2 years
    Works too! And if have scape caracteres like \n \t you can add .trim() getting like this: $("#yourdropdownid").children("option").filter(":selected").‌​text().trim();