Totally and whole heartedly agree :)

It was late and I was kinda only seeing new Image() method.

My bad..

Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com



On Fri, Jan 9, 2009 at 9:23 PM, Karl Swedberg <k...@englishrules.com> wrote:
> 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

Reply via email to