I am attempting to use jQuery to determine if an image has properly loaded.
The following works just fine (and returns true
or false
as of
Yes, I was just working on an AJAX page that dynamically loaded images. I also wanted to detect if images were loaded so I could transition them in with a jQuery effect.
img = $('myImageID')
img[0].src = 'http://new.url.for.image/';
alert(img[0].complete); // seems to always return true
// in Firefox, perhaps because
// the original src had been loaded
So instead I had to do this...
img = $('myImageID')
newImg = $('
') // create a completely new IMG element
.attr('src', 'http://new.url.for.image/')
.attr('id', img[0].id);
img.replaceWith(newImg);
img = newImg;
alert(img[0].complete);
(Note: I haven't tested this exact code, it's a simplified version of what I was trying to do, but hopefully communicates the idea.)
Simon.