0

I am trying to build a to-do list and I get this error msg:Uncaught TypeError: Cannot read properties of null (reading 'addEventListener').

I have looked through the code many times and I am unable to see what the problem is.

Here is my HTML

  <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>To Do List</title>
        <link rel="stylesheet" href="ToDoList.CSS">
    </head>
    <body>
        <section>
            <h1>To Do List</h1>
            <input type="text" id="userInputText">
            <button id="button">Submit</button>
            <p id="paragraph"></p>
        </section>






    <script src="ToDoList.JS"></script>
</body>
</html>

Here is my JS

let text = document.getElementById ('#userInputText');
let button1= document.getElementById ('#button');
let todolist = document.getElementById ('#paragraph');


function letsTry(){
    todolist.innerHTML=text.value;
}

button1.addEventListener('Click', letsTry)
  • You should not add `#` when using `getElementById` - you're already supplying the ID itself, no need to use the CSS selector notation for ID. – VLAZ Sep 21 '22 at 06:51
  • remove the `#` from the `getElementById`. You are already using the `getElementById`, therefore you don't need the hash in front. https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById – nosTa Sep 21 '22 at 06:51

0 Answers0