scrollWidth property in javascript
scrollWidth property is used to get the total width of the elements content, including the hidden contents due to scroll bar.
When the width is calculated it includes elements padding, but it does not include scroll bar size.
Syntax
var elem = element.scrollWidth;
Example Explanation
- In the above example, 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 in attr variable.
- Using the scrollWidth property, we are getting the width of the content present inside div element, and displaying it (alert (attr.scrollWidth)).