Pre-recorded question

Question #89
How to set HTML drop-down by value in jQuery?
Answer

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');

3 events in history
Question by Alphonsio 06/15/2020 at 03:16:51 PM
How to set HTML drop-down by value in jQuery?
Question by Alphonsio 06/15/2020 at 03:16:00 PM
How to set HTML selector to a given value in jQuery?
Answer by Alphonsio 06/15/2020 at 03:15:26 PM

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

Icons proudly provided by Friconix.