It is my code:
const square = document.getElementById('square');
square.addEventListener('click', function() {
alert("Red square");
});
Hello! Why I get “Uncaught TypeError: Cannot read properties of null (reading ‘addEventListener’)” ?
changing click to onclick doesn’t help.
I’ve changed the quotation marks too.
New contributor
kir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.