Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get image height in IE of display:none image?

I have images who are set to display:none. I am using javascript (document.getElementById('elem').height) to get the height/width of these images.

This works in other browsers, but IE reports the height to be 0 (presumably due to the fact that its display is set to none - because when I remove the display:none, the height is reported correctly). I tried wrapping the images in a div and setting the div's display to none instead of the images - but this didn't work either.

What is the typical work around for this?

like image 476
john Avatar asked Feb 21 '11 14:02

john


1 Answers

If you are interested in the size of the image itself, apart from any styles or attributes set in the html, you can measure a new Image with the same src.

It doesn't add anything to the document's html or stylesheets, or even to document.images.length if you are only testing included images.

var  im=new Image();
im.src=element.src;
return [im.src,  im.width, im.height];
like image 85
kennebec Avatar answered Oct 03 '22 12:10

kennebec