clientWidth property in javascript
clientWidth property is used to find the inner width of an element.
If the element doest contain any CSS or inline layout boxes, it returns zero.
This property calculates the width as, CSS width + CSS padding - height of vertical scroll bar.
Syntax
var elem = element.clientWidth;
Example Explanation
- In the above example we have created a div (idDiv), and have specified width and padding for the element.
- When the button is clicked, fun_name function is called.
- In the Javascript function, first we are getting the element (document.getElementById("idDiv")) and storing it in elem variable.
- Using the clientWidth property, the width is calculated and displayed (alert(elem.clientHeight)).