[jQuery] A definitive way to wait all images are loaded

[jQuery] A definitive way to wait all images are loaded


Hi, I've searched in the list but didn't find the way to solve.
I'm using jquery to change the position of different elements, but
these positions depends on the image size of multiple images on the
page.
If I use document.ready jquery start to work before all sensible
images are loaded.
I found in a discussion the js method to wait an image is loaded:
img = $('<img>');
img.attr('src', 'path/to/image.jpeg');
img[0].onload = function() {
dosomething();
}
But this method is ok if I want to wait for only one image.
In the past i solved putting nested img load functions:
img = $('<img>');
img.attr('src', 'path/to/image.jpeg');
img1 = $('<img>');
img.attr('src', 'path/to/image1.jpeg');
img[0].onload = function() {
img1[0].onload = function () {
dosomething();
}
}
Is there a better way to do this?
Thank you