I have 4 images on a page. I want to trigger a JS event once all 4 images are loaded. I of course can't be sure which order the images will be loaded in, so I can't trigger the event on the last image. One thought was to have a counter, but I can't think of the best way to check when that counter is equal to 4 as I don't like the idea of a setTimeout() checking every 200ms.

Any other ideas?

I'm using jQuery on the site, so I'm thinking that might be some help.

Unless these are the only four images on your page, however, you'll want to assign them a class or otherwise have some way to select just those four from your document. (e.g. $("img.dynloaded").load(…))
–
Ben BlankJan 6 '09 at 0:08

Yes exactly, because the $("img") selector is selecting every <img> tag on the page
–
Andreas GrechJan 6 '09 at 0:10

1

Thanks, just what I needed, in combination with: var noImages = $("img").size(); instead of 4 to make it more flexible...
–
jeroenApr 30 '09 at 23:29

jeroen, thanks for the comment; I updated the function now ;-)
–
Andreas GrechMay 1 '09 at 0:52