Say I have this markup
<div id="imageDiv">
<img src="/img/1.jpg" />
<img src="/img/2.jpg" />
<img src="/img/3.jpg" />
<img src="/img/4.jpg" />
<img src="/img/5.jpg" />
</div>
What I want to do is run a function, but only after all the images have loaded in. Now, I haven't any actual code to show, but the only way I can see to do this is this (psuedo-code, so untested)
function imagesReady(){
$.each(imageReady, function(key, val){
if (!val){
return;
}
});
nowDoTheMainFunction();
}
var imageReady = [];
$.each(imageDiv, function(key,imageElement){
imageReady[key] = false;
imageElement.addLoadListener(function(){
imageReady[key] = true;
imagesReady();
});
});
Is there a neater/better way than that to do this?