How can I detect when an image has finished loading be it from the server or the browser cache?
I want to load various images in the same tag and d
Everyone mentioned that the event should be fired before set to the src.
But if you don't want to worry about it, you can use the oncomplete event (will be fired even with cached images) to fire onload, like this:
$("img").one("load", function() {
// do stuff
}).each(function() {
if(this.complete) $(this).load();
});
Using jQuery you don't have to worry about backward compatibility (eg: img.height>0 in IE)