How to set HTML selector to a given value in jQuery?
The best way to select a given option in a HTML drop-down selector (<select><option>
) is to use the .val()
method. Let's consider the following example:
<select id="mySelector">
<option value="option1">Choice 1</option>
<option value="option2">Choice 2</option>
<option value="option3">Choice 3</option>
</select>
The following jQuery set option2
as selected:
// Selection option 2 from drop-down list with ID mySelector
$('#mySelector').val('option2');
The best way to select a given option in a HTML drop-down selector (<select><option>
) is to use the .val()
method. Let's consider the following example:
<select id="mySelector">
<option value="option1">Choice 1</option>
<option value="option2">Choice 2</option>
<option value="option3">Choice 3</option>
</select>
The following jQuery set option2
as selected:
// Selection option 2 from drop-down list with ID mySelector
$('#mySelector').val('option2');
# | ID | Query | URL | Count |
---|