JavaScript/jQuery event listener on image load IE issues

IE supports attachEvent instead. image.attachEvent(“onload”, function() { // … }); With jQuery, you can just write $(image).load(function() { // … }); When it comes to events, if you have the possibility of using jQuery I would suggest using it because it will take care of browser compatibility. Your code will work on all major browser … Read more

Detect image load

You can use the .load() event handler, like this: $(“#myImg”).load(function() { alert(‘I loaded!’); }).attr(‘src’, ‘myImage.jpg’); Be sure to attach it before setting the source, or the event may have fired before you attached a handler to listen for it (e.g. loading from cache). If that’s not doable (setting the src after binding), be sure to … Read more