1

What is the difference between Element.scrollHeight and the height returned by the JQuery $(ElementSelector).height() method.

I have seen this and this and I know that scrollHeight is the height of content, including the content which overflows outside the viewport. My question is that isn't that the same as the height returned by the height() method. I wrote this JSFiddle as a test of that.

Community
  • 1
  • 1
Solace
  • 8,612
  • 22
  • 95
  • 183

2 Answers2

3

Another difference is...

The height property sets the height of an element and does not include padding, borders, or margins; it sets the height of the area inside the padding, border, and margin of the element.

scrollHeight includes the element's padding, but not its border or margin.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight

Benneb10
  • 1,419
  • 1
  • 8
  • 13
0

height():

returns the actual height of an element in pixels.

scrollHeight():

is a measurement of the height of an element's content including content not visible on the screen due to overflow

Learn more about Box Model.

Saurav Rastogi
  • 9,575
  • 3
  • 29
  • 41