3

I m having a function to get the image width and height but that is not responding to the new images being loaded via a ajax call.

The function being -

$('img').on('load',function() {
    console.log(this.width + 'x' + this.height);
});

but i m adding DOM to the page using ajax call but the above code is not responding to the new images being loaded

My example page being here in the link with the console logs.

Regards

Pradyut Bhattacharya
  • 5,440
  • 13
  • 53
  • 83

2 Answers2

0

you need to do it in this way

$("img").one("load", function() {

}).each(function() {
  if(this.complete){
   console.log(this.width + 'x' + this.height);
 }
});

Updated

$("div.albumList").on("load","img", function() {
      console.log(this.width + 'x' + this.height);

  });
Ramzan Zafar
  • 1,562
  • 2
  • 17
  • 18
0

Well it is to be done as said by Rafael Diaz

$.ajax({
        type: "POST",
        url: 'bAlbum.jsp',
        data: null ,
        cache: false,
        success: function(html){
            $('ol#imagelist').append(html);               

            $("ol#imagelist li").each( function (i, e)
            {

               $(e).find('img').one('load', function() {
                   console.log(this.width + 'x' + this.height);
               });
            });
        }
    });
Community
  • 1
  • 1
Pradyut Bhattacharya
  • 5,440
  • 13
  • 53
  • 83