I'm trying to toggle check on a li target but every time I try, I get the error
"Uncaught TypeError: Cannot read property 'addEventListener' of null."
From what I can gather, it might be part of the JavaScript or html but I can't tell. So, what is another way or potential solve to properly adding an eventlistner to the list target.
JavaScript Function
document.getElementById("tasks").addEventListener("click", function(e) {
if (e.target.nodeName && e.target == "LI") {
e.target.classList.toggle("checked");
}
});
HTML Code
<form name="todolist" id="list">
<ul id="tasks">
<li class="checked">
One
</li>
<li>
Two
</li>
</ul>
</form>