Uncaught TypeError: Cannot read property 'addEventListener' of null at

Introduction to JavaScript Lesson 1, Step 4: Writing JavaScript in Chrome Developer Tools error

Trying to learn the language, and can’t through the first lesson without an error…

Uncaught TypeError: Cannot read property ‘addEventListener’ of null
at FirstProgram.JS.html:8

<html>
<head>
  <title>Intro to Programming JS  Lesson 1.4</title>
</head>
<body>
  <button id-"say-hi">Say Hi</button>
  <script>
    document.getElementById("say-hi").addEventListener("click", function() 
	{console.log("Hi");}
	);
  </script>
</body>
</html>

Correct sir the id-“say-hi” to id=“say-hi”.
You have write false the id in button element.Many of the errors that we have are producing due to this wrong syntax.

2 Likes

What can you see that is wrong with the above?

If you can’t spot it run the above code through the html validator :slight_smile:

Edit ; whoops too slow :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.