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
});
From the jQuery.each() documentation:
.each( function(index, Element) )
function(index, Element)A function to execute for each matched element.
So you'll want to use:
$('#list option').each(function(i,e){
//do stuff
});
...where index will be the index and element will be the option element in list
jQuery takes care of this for you. The first argument to your .each()
callback function is the index of the current iteration of the loop. The second being the current matched DOM element So:
$('#list option').each(function(index, element){
alert("Iteration: " + index)
});
$('#list option').each(function(intIndex){
//do stuff
});
Source: Stackoverflow.com