How Do I Determine scrollHeight?

How Do I Determine scrollHeight?

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

3

3 Answers

Correct ways in jQuery are -

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

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

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

You can also use:

$('#test').context.scrollHeight

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.