Update chatroom.HTML

This commit is contained in:
Dangrainage 2023-08-28 18:50:58 +02:00 committed by GitHub
parent 2b04a655da
commit 0496be4e8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,9 +34,7 @@
const messageInput = document.getElementById('message');
const sendButton = document.getElementById('send');
sendButton.addEventListener('click', sendMessage);
function sendMessage() {
sendButton.addEventListener('click', () => {
const message = messageInput.value;
if (message.trim() !== '') {
const messageElement = document.createElement('div');
@ -45,11 +43,11 @@
chatbox.scrollTop = chatbox.scrollHeight; // Scroll to the bottom
messageInput.value = '';
}
}
});
messageInput.addEventListener('keyup', function(event) {
messageInput.addEventListener('keyup', (event) => {
if (event.key === 'Enter') {
sendMessage();
sendButton.click();
}
});
</script>