AllThingsSmitty/jquery-tips-everyone-should-know

Preload Images Possible Bug

JoshWillik opened this issue · 2 comments

You have this code to preload images:

$.preloadImages = function () {
  for (var i = 0; i < arguments.length; i++) {
    $('img').attr('src', arguments[i]);
  }
}

If I'm not mistaken, that should set every image on the page to the last image passed, since you select all the images with $('img').

To create an in memory element each time, use $('<img>')

Good catch!!! I think you could submit a pull request.

I fixed this when I was linting some of the snippets. Thanks.