My select
options do not have value
attribute
<select id='1'>
<option>Label1</option>
<option>Label2</option>
</select>
I know how I would set by value :
$("#1").val("whatever");
How can I set an option by innerHTML ?
I tried
$("#1").html("Label1");
You would still set it with .val()
:
$("#1").val("Label2");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <select id='1'> <option>Label1</option> <option>Label2</option> </select>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.