1

This problem has been bordering me since day one:

if i got an image and I resize it with css:

.img {
width:100%;
height:auto;
}

and let's say I am gonna get the height of this image, by using

var imgH = $('.img').height();

imgH will be returned in 0, but I wanna get the height which's the size that's been processed by the css, how to tackle?

Thanks!


Sorry guys you are right, I tried the examples and tested it on my client's project, they are turned out all working, and I tried to reproduce the value 0 error but I fail to. I kinda lost in this while I still remember I trapped in this for a few times before. Anyway, problem solved, Thanks to @SrinivasR!:)

WJ___
  • 137
  • 1
  • 2
  • 13

1 Answers1

7
$(document).ready(function() {
    $("img").load(function() {
        alert($(this).height());
        alert($(this).width());
    });
});

DEMO

SRy
  • 2,743
  • 7
  • 33
  • 54