I am currently developing a chat application where messages are displayed in a background. I have used CSS to add an overflow scrollbar with the line overflow-y: scroll;
. Everything is working properly, but I'm wondering if there is a way to automatically scroll to the bottom of the chat window where the newest messages are displayed. This functionality can also be implemented using JavaScript.
Here is an example of my HTML code:
<article id="chat">
<script src="chat.js"></script>
</article>
Each message will follow this format and will be added to the article dynamically:
"<p class='msg'>" + msg + "</p>"