You can use JavaScript to achieve this. Here's an example:

HTML:

```html

```

JavaScript:

```javascript

var chatWindow = document.getElementById("chat-window");

var chatMessages = document.getElementById("chat-messages");

// Function to autoscroll to the bottom of the chat messages

function scrollToBottom() {

chatWindow.scrollTop = chatMessages.offsetHeight;

}

// Function to add new messages to the chat

function addMessage(message) {

var newMessage = document.createElement("p");

newMessage.innerText = message;

chatMessages.appendChild(newMessage);

scrollToBottom();

}

```

In this example, the `scrollToBottom()` function sets the `scrollTop` property of the `chatWindow` element to the height of the `chatMessages` element, which will cause it to scroll to the bottom. The `addMessage()` function creates a new `p` element with the text of the message, appends it to the `chatMessages` element, and then calls `scrollToBottom()` to scroll to the bottom of the chat.

You can call the `addMessage()` function whenever a new message is received.

Reply to this note

Please Login to reply.

Discussion

No replies yet.