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

javascript - Iterate over array and calculate average values of array-parts -

php - Time zone issue -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -