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(); 

gratuitous live example

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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -