apps.js:7 Uncaught TypeError: Cannot read property 'addEventListener' of null
I have this error.
Here's my HTML code
<!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">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="./style/style.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />
<title>Todo List</title>
</head>
<body>
<header>
<h1>Todo List</h1>
</header>
<form >
<input type="text" class="todo-input">
<button class="todo-btn" type="submit">
<i class="fas fa-plus-square"></i>
</button>
</form>
<div class="todo-container">
<ul class="todo-list">
</ul>
</div>
<script src="./js/apps.js" defer></script>
</body>
</html>
Here's my JS code
//Selectors
const todoInput = document.querySelector('todo-input');
const todoButton = document.querySelector('todo-btn');
const todoList = document.querySelector('todo-list');
//Event Listeners
todoButton.addEventListener("click", addTodo);
//Functions
function addTodo(event){
//Prevent form from submitting
event.preventDefault();
//Todo DIV
const todoDiv = document.createElement("div");
//Create LI
const newTodo = document.createElement('li');
newTodo.innerText = 'hey';
newTodo.classList.add('todo-item');
todoDiv.appendChild(newTodo)
//CHECK MARK BUTTON
const completedButton = document.createElement('button');
completedButton.innerHTML = '<i class="fas fa-check"></i>'
completedButton.classList.add("complete-btn");
todoDiv.appendChild(completedButton);
//CHECK trash BUTTON
const trashButton = document.createElement('button')
trashButton.innerHTML = '<i class="fas fa-check"></i>'
trashButton.classList.add("complete-btn");
todoDiv.appendChild(trashButton);
//APPEND TO LIST
todoList.appendChild(todoDiv);
}
I am currently refreshing my skills with javascript. I am shadowing someone's work on youtube and came across with this error. Can anyone explain and enlighten me about the error and how to fix it? Thank you!
Can anyone help me with my problem? Thank you so much