On Jan 9, 2009, at 9:11 AM, jQuery Lover wrote:
Here is something from top of my head: $(function () { var imgs = new Array(); imgs[0] = 'images1.jpg'; imgs[2] = 'images2.jpg'; imgs[3] = 'images3.jpg'; imgs[4] = 'images4.jpg'; imgs[5] = 'images5.jpg'; var $img = new Image(); for(var i in imgs){ $($img) .load(function () { checkFinal(); }) .attr('src', imgs[i]); } });
The above seems a little overkill to me. I'm not sure why, for example, you need to declare var imgs = new Array() and why you skip imgs[1]. Also, I think it makes more sense to use a plain for loop rather than a for-in loop when iterating through an array. I might be missing something, but couldn't it be done more simply like this? ...
for (var i=1; i <= 5; i++) { $('<img/>') .attr('src', 'images'+i+'.jpg') .load(function () { checkFinal(); }); } --Karl