2

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.

Community
  • 1
  • 1
understack
  • 10,882
  • 24
  • 75
  • 98

3 Answers3

0

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);
Alex Polkhovsky
  • 3,258
  • 5
  • 27
  • 36
0

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
  • 4,143
  • 1
  • 24
  • 36
0

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
  • 697
  • 4
  • 11
  • 29