SHARE
TWEET

Untitled

a guest May 30th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var msgTemplateContent = document.querySelector('#message-template').content;
  2. var inputForWriteMsg = document.querySelector('.chat-form-input');
  3. var formToSendMsg = document.querySelector('.chat-form');
  4. var chatWindow = document.querySelector('.chat-content');
  5.  
  6. var addNewMessage = function(msgText) {
  7.   if ( msgText.length >= 1 ) {
  8.     var msgContent = msgTemplateContent.cloneNode(true);
  9.    
  10.     msgContent.querySelector('.chat-message-text').textContent = msgText;
  11.  
  12.     var deleteMsgElement = msgContent.querySelector('.chat-message-button');
  13.     deleteMsgElement.addEventListener('click', function() {
  14.       msgContent.remove();
  15.     });
  16.    
  17.     chatWindow.appendChild(msgContent);
  18.    
  19.   }
  20. }
  21.  
  22. formToSendMsg.addEventListener('submit', function(evt) {
  23.   evt.preventDefault();
  24.   addNewMessage(inputForWriteMsg.value);
  25.   inputForWriteMsg.value = '';
  26. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top