Hi im trying to create a toDo list - when i press on the checkbox, the task completion should change to true. As there are several checkboxes, i have used the class element, however, when i try to add an event listener, it doesn't seem to let me. There are also large gaps between each text, the checkboxes were supposed to be there but i moved them, but the gaps still appear. Could someone please help. Thank you.
Im a noob at Javascript, and i wish to get better. Do you guys have tips on how to get better, also. Thank you.
const todos = [{
task: "Revision",
completed : false
},{
task: "Walk Dog",
completed : false
},{
task: "Read Book",
completed : false
},{
task: "Javascript Practice",
completed : false
},{
task: "VB.Net Practice",
completed : false
},{
task: "Gaming",
completed : false
}]
todos.forEach(function(todos) {
const list = document.createElement("h3")
list.textContent = `${todos.task} - ${todos.completed}`
document.getElementById("output").appendChild(list)
const button = document.createElement("input")
button.type = "checkbox"
button.setAttribute("class", "checkboxes")
document.getElementById("output").appendChild(button)
})
const complete = document.getElementsByClassName("checkboxes")
complete.addEventListener("click", function() {
todos.completed == true
})
body {
font-family: quicksand;
}
.checkboxes {
position: relative;
left: 250px;
bottom: 40px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>ToDo List</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>ToDo List</h1>
<div id="output">
</div>
<script src="todo.js"></script>
</body>
</html>