views:

241

answers:

3

If a web page is zoomed out/in in any modern browser, then how I can find size of a DIV element at 100% zoom?

EDIT:: I asked another similar question here, which was unanswered.

A: 

Do you know the original size? At least in IE7+ you can figure out zoom level and figure out the proportions:

zoomLevel = Math.round((self.document.body.parentElement.offsetWidth / self.document.body.offsetWidth) * 100);
LymanZerga
also see this:http://stackoverflow.com/questions/995914/catch-browsers-zoom-event-in-javascript
LymanZerga
A: 

If you're using jQuery, you can use the $('#div').width() or $('#div').outerWidth() method to find it very easily. There are equivalents in other JS libraries, so just ask if you want to know the method in your framework of choice

Gausie
This doesn't work. Please see my edit in the question.
understack
A: 

You can use pure JavaScript to get the width and height like so:

// Create an object of the div.
var divElement = document.getElementById('id of div');

// Retrieve the height and width.   
var width = divElement.getAttribute('width');
var height = divElement.getAttribute('height');

It's possible to do the same thing with jQuery or any other library and it's generally faster and easier that way.

John Swaringen
This won't work if page is zoomed in/out. See my edit in the question.
understack