jQuery Select Droplist by Value

March 12, 2011

Say we have a droplist (<select>) on a web page, and we want to use jQuery to select one of the items.

Given the following select:

<select id="mySelect">
  <option value="A">First</option>
  <option value="B">Second</option>
  <option value="C">Third</option>
  <option value="D">Fourth</option>
  <option value="E">Fifth</option>
</select>

You can select the one you want using:

$('#mySelect option[value=C]').attr('selected', 'selected');

References