Friday, December 8, 2017

How do I get the text value of a selected option in jQuery

<select id="myselect">
<option value="1">Mr</option>
<option value="2">Mrs</option>
<option value="3">Ms</option>
<option value="4">Dr</option>
<option value="5">Prof</option>
</select>
I$( "#myselect" ).val();
// => 1
$( "#myselect option:selected" ).text();
// => "Mr"

No comments:

Post a Comment