2

On the initial page load, the image load callback gets invoked. I use knockout to add dynamic images to the page. When I do that, however, the image load callback is not being invoked. Is there a work around for that?

$(function(){
    $("img").on("load", function () { 
       console.log("loaded");
    });
});
0

2 Answers 2

1

It's likely the onload event has occurred before you've attached the listener, so you could try...

$("img").on("load", function() { 
  // your onload code
}).each(function() {
    // in case it's already loaded
    if(this.complete) $(this).load();
});

-1
var img = new Image();
img.onload = function () {
   alert("image is loaded");
}
img.src = "img.jpg";

give it a try

Not the answer you're looking for? Browse other questions tagged or ask your own question.