I’m trying to find an option’s index.
For example, I would like to get 1 when I run the following fake code
JS:
$("#test[value='USD']").index() ?
HTML:
<select id='test'>
<option value='CNY'>CNY</option>
<option value='USD'>USD</option>
</select>
is this possible?
You were very close, you want to use
indexon theoptionelement, not theselect:Gratuitous live example
Note that this will break if your
selectcontainsoptgroupelements. If so, you’ll want to pass'option'intoindex:Live example (I changed the position so it’s the 4th element for that example)