Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .load() not working on my image

Tags:

jquery

I have some code I am trying to run once my image has finished loading. I use this following jQuery code:

$("#myimageid").load(function() {     alert('Image Loaded'); }); 

However the popup never show up. I can't get the .load() function to work ! Anyone had issues with this?

like image 865
Etienne Dupuis Avatar asked Aug 27 '10 21:08

Etienne Dupuis


1 Answers

If you're running this after the image already has a set source, you need to do an additional check for caches images (who fired the event, just before you added an event handler listening for it). You can do that like this:

$("#myimageid").on('load', function() {   alert('Image Loaded');  }).each(function() {   if(this.complete) $(this).load(); }); 

Update for later versions of query, use:

if(this.complete) $(this).trigger('load'); 

Using (this).load(); will produce a Cannot read property 'indexOf' of undefined error

like image 180
Nick Craver Avatar answered Sep 20 '22 19:09

Nick Craver