I tried adding a serialized class to each of a set of objects like this:
jQuery('#preload img').each(function(){ jQuery('#thumbs').append('<img class="index' + index + '" src="' + source + '" />'); index = ++index; });
And it worked. What resulted was a set of images, each with a class image1, image2, and so on. It’s exactly what I wanted. But is this actually a reliable method of looping through a set of objects? Or is it possible that, if this anonymous function took longer to execute, the function might start on the next object before index is incremented?
Anybody know what’s actually happening?
This is the inner workings of the
eachfunction (1.4.4):You can see here that it has a few different cases but all of them use
forloops and call the callback function. So your code should be fine.You can look it up in the development version of jQuery (change the radio button on the main jQuery site, or click here).