jquery - How to find select option position? -
i'm trying find option's index.
for example, 1 when run following fake code
js:
$("#test[value='usd']").index() ?
html:
<select id='test'> <option value='cny'>cny</option> <option value='usd'>usd</option> </select>
is possible?
you close, want use index
on option
element, not select
:
var = $("#test option[value='usd']").index();
note break if select
contains optgroup
elements. if so, you'll want pass 'option'
index
:
var = $("#test option[value='usd']").index('option');
live example (i changed position it's 4th element example)
Comments
Post a Comment