Find Scroll Height for elements using jQuery

.Height() method in jQuery returns height of the element but assume an element which has "overflow:auto" property set (you will find scroll bars) and its content are going beyond to the initially defined height. So in such case, jQuery .Height() method will not give you the scroll height.

One need to use scrollHeight property to get height of the scroll view of an element.

If you are using jQuery 1.7 or higher version then use prop(), otherwise use attr(). In the code sample, I have used "prop()" to get value of "scrollHeight" property.

$(document).ready(function() {
  //Get height of the div
  var iHeight = $("#dvContent").height();
  //Get ScrollHeight of the div
  var iScrollHeight = $("#dvContent").prop("scrollHeight");
  var msg = 'Height:' + iHeight + 'px & ScrollHeight:' + iScrollHeight + 'px';


See result below.

See Complete Code

Feel free to contact me for any help related to jQuery, I will gladly help you.

Responsive Menu
Add more content here...