Suppose that I have a <div> that I wish to center in the browser's display (viewport). To do so, I need to calculate the width and height of the <div> element.
What should I use? Please include information on browser compatibility.
Try using the .offsetWidth and .offsetHeight properties.
var width = document.getElementById('foo').offsetWidth;
Note: They belong to the element, not to the .style.