Почему пишет " TypeError
: Cannot read property ‘addEventListener’ of null " ?
Код
var varForm = document.querySelector(‘chat-form’);
var varChat = document.querySelector(’.chat-content’);
var input = document.querySelector(’.chat-form-input’);
var varTemp = document.querySelector(’#message-template’).content;
var message = varTemp.querySelector(’.chat-message’);
var messageRemoover = function (message) {
var remButton = message.querySelector(’.chat-message-button’);
remButton.addEventListener(‘click’, function () {
message.remove();
})
};
varForm.addEventListener(‘submit’, function(evt) {
evt.preventDefault();
var newMessage = message.cloneNode(true);
var text = newMessage.querySelector(’.chat-message-text’);
var name = newMessage.querySelector(’.chat-message-name’);
var value = input.value;
text.textContent = value;
input.value = “”;
varChat.appendChild(newMessage);
messageRemoover(newMessage);
});