var imgLoader = $("<img />");
$(imgLoader).attr("src", "http://localhost/malevil/Content/Images/img_adrenalin.jpg");
$(imgLoader).unbind('load');
$(imgLoader).bind('load', function () {
alert("event fired");
});
But this work only in chrome, where is the problem ? In IE, Firefox and Opera load event never fired.
You need to bind the load event before you set the src
property.
As a side note, there are known issues with the load event on images that you need to be aware of:
And, quoting from the jQuery manual on load()
:
- It doesn't work consistently nor reliably cross-browser
- It doesn't fire correctly in WebKit if the image src is set to the same src as before
- It doesn't correctly bubble up the DOM tree
- Can cease to fire for images that already live in the browser's cache
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With