auto scroll down when new div is added code example
Example: auto scroll a div
<style>
// NOTE: to auto scroll a div smoothly
#direct-chat-messages
{
scroll-behavior: smooth;
}
</style>
<script>
// NOTE: to auto scroll a div.
window.setTimeout(function() {
var elem = document.getElementById('direct-chat-messages');
elem.scrollTop = elem.scrollHeight;
}, 100);
</script>