0

Why jQuery .width is returning 0 instead of 1. I am loading image from 3rd party and it take a while to load. how can I load image first and then grab the image width?

     $(document).ready(function(){

    $("#dealerChatSmallButtonHeader a img").one('load', function() {
      var chatButtonWidth = $('#dealerChatSmallButtonHeader a img');
   console.log(chatButtonWidth.width());
   if(chatButtonWidth.width() != 0)
          {
            $('#dealerChatSmallHeader').css('display','inline');
            $('#dealerChatSmallBody').css('display','inline');
            $('#dealerChatLarge').css('display','block');
          }
    }).each(function() {
      if(this.complete) $(this).load();
    });
 });
Pascal
  • 1,288
  • 8
  • 13
Shoaib Ud-Din
  • 4,614
  • 3
  • 23
  • 23
  • Why should it return 1? What's the HTML? What image are you loading? What's the CSS for the img? You can use $('img').load(function() {...}); to do something on image load – Vincent McNabb Jul 10 '13 at 02:24
  • The image I am loading from 3rd party sometime it gives me 1x1 px image and sometimes more than 1px width but the image source is always same. – Shoaib Ud-Din Jul 10 '13 at 02:27

0 Answers0