WJ___
WJ___

Reputation: 137

Is there a way to get an image's width which's auto in css?

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!:)

Upvotes: 1

Views: 94

Answers (1)

SRy
SRy

Reputation: 2967

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

DEMO

Upvotes: 7

Related Questions