Search code examples
jqueryhtmlimageheightsrc

Firefox (via jQuery) reports wrong height for image without src attribute


http://jsfiddle.net/2N854/

html:

<img alt="test" width="100" height="100">

javascript:

alert($('img').height());

On most browsers (chrome), the alert displays "100" as one would expect. On firefox, it does not. It "helpfully" converts the img into something that looks like:

<div>test</div>

.. and reports the height of that - "19" in my case. I can work around the problem by assigning a placeholder src right before I check the height, and that works ok.

I didn't really forget the src attribute, rather I am in the process of computing it client-side.

I guess my question is - is there some way to disable this firefox "helpfulness"?


Solution

  • Yes, you can assign display: inline-block to your image - http://jsfiddle.net/2N854/1/ and FF will behave :)