scrollHeight in javascript

scrollHeight property in javascript

scrollHeight property is used to get the total height of the elements content, including the hidden contents due to scroll bar.

When the height is calculated it includes elements padding, but it does not include scroll bar size.


var elem = element.scrollHeight;

Example - Getting the scrollHeight of an element

Try Yourself

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 it in attr variable.
  • Using the scrollHeight property, we are getting the height of the content present inside div element, and displaying it (alert (attr.ScrollHeight)).