Check if images are loaded?

The text from the .ready jQuery docs might help make the distinction between load and ready more clear:

While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received. In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code.

… and from the .load docs:

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

So .load is what you’re looking for. What’s great about this event is that you can attach it to only a subset of the DOM. Let’s say you have your slideshow images in a div like this:

<div class="slideshow" style="display:none">
  <img src="https://stackoverflow.com/questions/5424055/image1.png"/>
  <img src="image2.png"/>
  <img src="image3.png"/>
  <img src="image4.png"/>
  <img src="image5.png"/>
</div>

… then you could use .load just on the .slideshow container to trigger once all of the images in the container have been loaded, regardless of other images on the page.

$('.slideshow img').load(function(){
  $('.slideshow').show().slideshowPlugin();
});

(I put in a display:none just as an example. It would hide the images while they load.)

Update (03.04.2013)
This method is deprecated since jQuery Version 1.8

Leave a Comment