jQuery Set Selected Option Using Next
Posted
by Dodinas
on Stack Overflow
See other posts from Stack Overflow
or by Dodinas
Published on 2009-08-14T21:42:20Z
Indexed on
2010/05/25
8:21 UTC
Read the original article
Hit count: 562
Hello,
How can I, using jQuery, set the "next" item of an already selected item as "selected."
For example, if I have:
<select>
<option value="1" >Number 1</option>
<option value="2" selected="selected">Number 2</option>
<option value="3" >Number 3</option>
<option value="4" >Number 4</option>
</select>
We can see that "Number 2" is selected, and using jQuery, I'd like to set "Number 3" as selected, and remove the selected "attribute" from "Number 2". I'm assuming I need to use the next selector, but I'm not quite sure how to implement.
Any ideas? Thanks!
© Stack Overflow or respective owner