Reputation: 5104
In my web chat application, in the chat window div, I want to always show the last line of the message. I have set overflow-y: auto, so that the vertical scroll bar will appear when it is necessary. But before the scroll bar appears, I don't have to point it to the last line. How do I know when the vertical scroll bar appears? The reason I need to do this is because when there is no vertical scroll bar, I use:
var height = $('#chatbox')[0].scrollHeight;
$('#chatbox').scrollTop(height);
to point to the last line, it always returns a javascript error says no object or null when the vertical scroll bar does not exist.
Upvotes: 0
Views: 837
Reputation: 92893
Compare $('#chatbox')[0].scrollHeight
to $('#chatbox')[0].clientHeight
. If they're equal, there is no scrollbar.
Upvotes: 3