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 Reply

Your email address will not be published. Required fields are marked *

*