I have some trouble with a HTML dropdown and jQuery.
One option is preselected
<select id="category">
<option value="1" selected="selected">Value 1</option>
<option value="2">Value 2</option>
</select>
I try to get the selected value with this line
$("#category").val();
But I get always the preselected option “1”.
Also variants like
$("select option:selected").val();
don’t work.
Any suggestions?
I think you need this:
DEMO
Because.
$('#category').val()will output you thevalueattribute of selected option.In order to get thetextof that selected option you need above.