$('img').height()
returns 0
in chrome, but it returns the actual height in IE and firefox.
Whats the actual method to get the height of the image in chrome?
$('img').height()
returns 0
in chrome, but it returns the actual height in IE and firefox.
Whats the actual method to get the height of the image in chrome?
My assumption is that this function is being called before the image is finished loading. Can you try putting a delay on the function to see if this is actually the case? If this is the case, you can cheat by using a timer before running the function.
It is a bit more complicated to detect when an image has been loaded. Have a look at this script for some ideas -- maybe it would work for you.
As Josh mentioned, if the image has not fully loaded yet, jQuery won't know what the dimensions are yet. Try something like this to ensure you're only attempting to access it's dimensions after the image has been completely loaded:
Just had the same issue: set the width and height beforehand via CSS or HTML.
Preloading the image and setting up a callback function might be what you're looking for:
A slightly ugly but effective fix that I used was use a backend language, in my case php, to get the height and set it on the image before sending it to the browser.
it's ugly, but simple and quick
Try using an image pre-loader, here's one I wrote for an answer to another question.