I am creating a chat using Ajax requests and I’m trying to get messages div to scroll to the bottom without much luck.
I am wrapping everything in this div:
JavaScript
x
5
1
#scroll {
2
height:400px;
3
overflow:scroll;
4
}
5
Is there a way to keep it scrolled to the bottom by default using JS?
Is there a way to keep it scrolled to the bottom after an ajax request?
Advertisement
Answer
Here’s what I use on my site:
JavaScript
1
3
1
var objDiv = document.getElementById("your_div");
2
objDiv.scrollTop = objDiv.scrollHeight;
3