For example, I would like to append selected="selected"
to the op开发者_JAVA百科tion that contains This one, which jQuery selector should be used to append attributes into that element?
<select>
<option>Not this</option>
<option>This one</option>
</select>
Thanks in advance!
If there are no value
attributes, then the text becomes the value, so you can just use .val()
:
$("select").val("This one");
Or, if it has a value="something"
attribute, use that instead:
$("select").val("something");
精彩评论