Advertisement
SimeonTs

5th - ChatRoom

Jun 6th, 2020
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     // First Let's grab the Input, Button and Chat Area:
  3.     let button = document.querySelector("#send");
  4.     let input = document.querySelector("#chat_input");
  5.     let area = document.querySelector("#chat_messages");
  6.  
  7.     // Now lets pace the listener:
  8.     button.addEventListener('click', function () {
  9.         // If we don't have any value we won't continue:
  10.         if (!input.value) { return; }
  11.  
  12.         // Lets Create the Message:
  13.         let message = document.createElement('div');
  14.         message.setAttribute("class", "message my-message");
  15.         message.innerText = input.value;
  16.  
  17.         // And Append the message to the Chat Area:
  18.         area.appendChild(message);
  19.  
  20.         // And clear the input field;
  21.         input.value = '';
  22.     });
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement