👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.

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>

The following jQuery set option2 as selected:

// Selection option 2 from drop-down list with ID mySelector