I have the code like below to get ‘content’ width, but how come it returns with different values for IE 7,8,9? The value is also different for Firefox.
How can I make it returns the consistent value? Is it possible without using JQuery?
document.getElementById('content').clientWidth
document.getElementById('leftSide').offsetWidth
document.getElementById('content').clientHeight
leftside div is contained inside of content div. The only style they have is
background-color:white;
I got:
IE7 1604/297/925
IE8 1906/297/925
IE9 1910/297/1609.
FF 1610/297/1910
I tried to switch on the “standards-compliant mode” but still didn’t make a difference…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Thanks,
The difference has to do with the browsers box model. Largely depends if you’re in quirks mode or not (http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug). The most effective way to mitigate these issues is to use JavaScript library that has methods for normalizing the differences between browsers (e.g., jQuery’s
.width().height()).