Jquery – Preloading images

When you’re using images in Javascript, a good thing is to preload it before you have to use it.

This code will do the job:

jQuery.preloadImages = function()
{
  for(var i = 0; i").attr("src", arguments[i]);
  }
};

// Usage

$.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg")

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>