If you're working in Javascript and your div has the id "scrolling"
, you can use the following code:
document.getElementById("scrolling").scrollTop = document.getElementById("scrolling").scrollHeight;
The scrollTop property represents the number of pixels the object is scrolled, while scrollHeight gives you the total height of the content within the element, including the parts that are not currently visible due to overflow.
It's important to note that this code should be run every time a new message appears in the chatbox, so make sure it's properly placed within your script.
For more information, check out these sources:
https://developer.mozilla.org/en-US/docs/DOM/element.scrollTop
https://developer.mozilla.org/en-US/docs/DOM/element.scrollHeight
Alternatively, you could consider using an anchor for the last message (#idOfLastMessage) and then using an iframe instead of a div that points to www.yoursite.com/url-of-the-message-list#idOfLastMessage