1

Im aware of ways to see when an image created with javascript or jquery has loaded, such as

.loaded(callback(){

})

or imagesLoaded library,

but how do i know when image created with a plain tag inside html document has loaded?

nuway
  • 2,324
  • 4
  • 27
  • 48

3 Answers3

0

$(window).load() waits for the DOM and all images to load, see this question.

Community
  • 1
  • 1
clav
  • 4,221
  • 30
  • 43
0

You can simply do this :

 <img src='my.jpg' id='myImage' />

    $("#myImage").on('load', function(){
      // image loaded .. do something
    });
XTop
  • 255
  • 2
  • 9
0

The primary issue is that the image may or may not be already loaded. I would just pre-load it as usual. If it's already loaded, the load event will still trigger.

$(function(){

    var src = $("#myimg")[0].src,
        img = new Image();

    $(img).load(function(){
        console.log('image loaded');
    })[0].src = src;

});
Kevin B
  • 94,570
  • 16
  • 163
  • 180