jQuery .each() index?

后端 未结 5 2012
盖世英雄少女心
盖世英雄少女心 2021-01-31 01:03

I am using

$(\'#list option\').each(function(){
//do stuff
});

to loop over the options in a list. I am wondering how I could get the index of

5条回答
  •  难免孤独
    2021-01-31 01:17

    surprise to see that no have given this syntax.

    .each syntax with data or collection

    jQuery.each(collection, callback(indexInArray, valueOfElement));
    

    OR

    jQuery.each( jQuery('#list option'), function(indexInArray, valueOfElement){
    //your code here
    }); 
    

提交回复
热议问题