Henry8
Henry8

Reputation: 264

Full width of image in jQuery

How can I know in jQuery the height of an image loaded with:

style="width:100%; height: auto;"

The width screen in mobile device is ever different, and i dont like the effect "jump" when the page is loading. I hope I was clear. Thanks

Upvotes: 0

Views: 74

Answers (2)

maverickosama92
maverickosama92

Reputation: 2725

try following (see if it helps :) ):

alert("width: " + $("#imgRandom").width() +"\nHeight:  "+$("#imgRandom").height() );

fiddle link: http://jsfiddle.net/6dnSM/

i hope it helps.

Upvotes: 1

BenM
BenM

Reputation: 53198

You can quite easily get the height using height() and outerHeight(), for example:

var imgHeight = $('img.image-class').height();

Or:

var imgHeight = $('img.image-class').outerHeight(false); // the argument indicates whether to include the margin

Upvotes: 0

Related Questions