Get text of the selected option with jQuery

dotty picture dotty · Jun 23, 2011 · Viewed 109.6k times · Source

I have a select box with some values. How do I get the selected options text, not the value?

<select name="options[2]" id="select_2">
    <option value="">-- Please Select --</option>
    <option value="6" price="0">100</option>
    <option value="7" price="0">125</option>
    <option value="8" price="0">150</option>
    <option value="9" price="0">175</option>
    <option value="10" price="0">200</option>
    <option value="3" price="0">25</option>
    <option value="4" price="0">50</option>
    <option value="5" price="0">75</option>
</select>

I tried this:

$j(document).ready(function(){
    $j("select#select_2").change(function(){
        val = $j("select#select_2:selected").text();
        alert(val);
    });
});

But it's coming back with undefined.

Answer

JohnP picture JohnP · Jun 23, 2011

Close, you can use

$('#select_2 option:selected').html()