One, JavaScript get HTML element width high
1. The width and height are written in the style table, such as #div1{width:120px;}. In this case, the width can not be obtained by #div1.style.width, but by #div1.offsetwidth.
2. Width and height are written in the middle of the line, such as style= "width:120px;", in this case through the above 2 methods can be achieved.
Summary, because clientwidth and offsetwidth ignore style written in the style sheet or line, so we get the element width and height when it is best to use these 2 attributes. Note If you do not write a property in a style within a row, you cannot get it through I**.STYLE.ATRR.
Today's front-end productions seldom write styles directly in style, they are written in the style table. If you want to get a style that does not correspond (like #div1.style.width corresponding to #div1.offsetwidth), you can only use the browser to get the style sheet properties, you may 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
Ii. the relationship between width, clientwidth and offsetwidth
Width is the contents of the HTML element
clientwidth = width + padding
offsetwidth = width + padding + border
JavaScript gets the actual width and height of the HTML element