I am creating an ajax chat in rails and I am trying to get a div to scroll to the bottom without much luck.
I am wrapping everything in this div:
#scroll {
height:400px;
overflow:scroll;
}
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?
Source: Tips4all
Here's what I use on my site (I didn't write it, I just found it somewhere since I don't know Javascript too well.)
ReplyDeletevar objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;
This is much easier if you're using jQuery:
ReplyDelete$("#mydiv").scrollTop($("#mydiv")[0].scrollHeight);