JS Advanced 05.Chat Room Dom-exercise
Здравейте, може ли да пуснете решение на задача Chat Room от DOM-exercise ??
Здравейте, може ли да пуснете решение на задача Chat Room от DOM-exercise ??
function solve() {
let sendButton = document.querySelector('button#send');
let sendTextarea = document.querySelector('textarea#chat_input');
let chatMessages = document.querySelector('div#chat_messages');
sendButton.addEventListener('click', (ev) => {
let message = sendTextarea.value;
let myMessage = document.createElement('div');
myMessage.classList.add('message');
myMessage.classList.add('my-message');
myMessage.textContent = message;
chatMessages.appendChild(myMessage);
sendTextarea.value = '';
});
}
function solve() {
// NB! Function w/o parenthesis to avoid returning the result and only execute it
document.getElementById('send').addEventListener("click", onClick);
let message = document.getElementById("chat_messages");
function onClick() {
// alert("Test");
const input = document.getElementById('chat_input');
const value = input.value;
let newDiv = document.createElement("div");
newDiv.className = "message my-message";
newDiv.innerText = value;
message.appendChild(newDiv);
input.value = "";
}
}