Skip to content Skip to sidebar Skip to footer

Clientwidth And Clientheight Returns 0

Why clientWidth/Height return 0 on IE, Chrome and Safari? but on Firefox and Opera works fine. I used this code: $(document).ready(function () { var imgs = document.getElement

Solution 1:

Try change doctype. http://forums.asp.net/post/1515655.aspx I'm not sure, but I solved this problem so.

Solution 2:

If you want to get dimensions including margins and borders try using JQuery functions outerWidth and outerHeight. They should take care about crossbrowser differences. http://api.jquery.com/outerwidth/

If you want to get only dimensions of an element contents (without margins, borders, paddings) use width and height. http://api.jquery.com/width/

Solution 3:

I think it would be better if you use JQuery to get the height and width, as it works fine in all browsers, so your code would be something like this :-

$(document).ready(function() {


     var imgs = $('img');
     var imgLength = imgs.length;

     for(var i=0; i<= imgLength-1;i++){

         var imgWidth = imgs[i].width();
         var imgHeight = imgs[i].height();

         $('img').eq(i).attr({width:imgWidth, height: imgHeight});

         console.log(imgWidth);
     }

     console.log(imgLength); 

});

Post a Comment for "Clientwidth And Clientheight Returns 0"