How do I determine scrollHeight?

JavascriptJquery

Javascript Problem Overview


How do I determine scrollHeight of a division use css overflow:auto?

I've tried:

$('test').scrollHeight();
$('test').height(); but that just returns the size of the div not all the content

Ultimately, I'm trying to create a chat and always have the scroll bar to the current message on the screen.

So I was thinking something like the following:

var test = $('test').height();
$('test').scrollTop(test);

Thank you,

Brian

Javascript Solutions


Solution 1 - Javascript

Correct ways in jQuery are -

  • $('#test').prop('scrollHeight') OR
  • $('#test')[0].scrollHeight OR
  • $('#test').get(0).scrollHeight

Solution 2 - Javascript

scrollHeight is a regular javascript property so you don't need jQuery.

var test = document.getElementById("foo").scrollHeight;

Solution 3 - Javascript

You can also use:

$('#test').context.scrollHeight

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrianView Question on Stackoverflow
Solution 1 - JavascriptAnmol SarafView Answer on Stackoverflow
Solution 2 - JavascriptDennisView Answer on Stackoverflow
Solution 3 - Javascriptslunt32View Answer on Stackoverflow