Using the "img" tag with only a width value in CSS will automatically calculate the height proportionally.
However, finding the height value using developer tools or jQuery's height() method may not work as expected. See the example below:
HTML code
<img id="cat" src="./cat.png"/>
CSS code
img#cat {
width:10em;
}
jQuery code
$(function() {
alert($('img#cat').height()); // Returns 0 due to no explicitly declared height value
});
Is there a suitable jQuery alternative for determining the image height?