The first is that the width and height are written in the style sheet, such as #div1{width:120px. In this case, the width can not be obtained through the #div1.style.width, but only through the #div1.offsetwidth.
The second situation is that wide and high is written in the line, such as style= "width:120px," which can be achieved by the above 2 methods to get width.
Summary, because Id.offsetwidth and id.offsetheight ignore styles written in style sheets or in rows, so it's best to use these 2 attributes when we get the element width and height. Note that if you do not write attributes in the inline style, you cannot get them by ID.STYLE.ATRR.
Now the front-end production is rarely directly to the style of writing, are written in the style table. If you want to get the style does not correspond (just like #div1.style.width corresponding #div1.offsetwidth), can only be for the browser to get the property of the style sheet, you can try to search "JS get style properties" and so on.
Code:
var o = document.getElementById ("view");
var h = o.offsetheight; Height
var w = o.offsetwidth;//width
The above JS to get the actual width of the HTML elements of the height of the method is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.