I was wondering if it’s possible to get jQuery to select an <option>
, say the 4th item, in a dropdown box?
<select>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select>
I want the user to click a link, then have the <select>
box change its value, as if the user has selected it by clicking on the <option>
.
How about
$('select>option:eq(3)').attr('selected', true);
example at http://www.jsfiddle.net/gaby/CWvwn/
for modern versions of jquery you should use the .prop()
instead of .attr()
$('select>option:eq(3)').prop('selected', true);
example at http://jsfiddle.net/gaby/CWvwn/1763/