I wanted write preloader images and I was stuck on the checking already lodead images:
var imgContainer = [];
$(this).find('img').each(function() {
imgContainer.push({
image: $(this)
// other properties
})
});
setInterval(function() {
console.log(imgContainer[0].image.complete); // undefined
}, 2000);
but this solution worked (without objects in array):
var imgContainer = $(this).find('img');
setInterval(function() {
console.log(imgContainer[0].complete) // true
}, 2000);
Why it's not working?
eventsounds like a really bad choice for that argument name. You do know you can usethisand make the function argument-less?image?eventis semantically incorrect it was used in the proper way as the second argument in the itterative function passed to the function each on a jQuery collection is the element in question for the relevant iteration.