I've been having an issue with using offsetWidth across different browsers. This difference in results is causing some strange layouts. I've created a very small example that displays what I'm seeing.
HTML
<table id="tbl">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>
<button onclick="calc()">Calculate Offset Width</button>
<div>Cell 1 offsetWidth: <span id="c1offWidth"></span></div>
js
function calc(){
document.getElementById('c1offWidth').innerHTML =
document.getElementById('tbl').children[0].children[0].offsetWidth;
}
CSS
When I run this on chrome, safari, and opera the value returned for Cell 1's offset width is 72. When I run this on firefox and IE9-10 the value returned is 77.
I was under the impression this was the best way to calculate the width of an element including padding and border.
Is there a cross browser solution that will always return the same result? I tried using jQuery but the results were even more confusing.
EDIT Because everyone is recommending outerWidth I made a jsbin for that also. The results still differ across browsers. Chrome returns 36; IE9-10 and Firefox return 39.