My mission in this exercise is to toggle the "done" attribute of the li items on the list whenever someone clicks on them. I found other ways of doing so, but this one didn't work for me and I'm eager to understand why. What's wrong with my code? isn't it possible to assign handlers like that, or maybe something else in my code is wrong?
var liList = document.querySelectorAll("li");
for (var i = 0; i < liList.length; ++i){
liList[i].onItemClick = function() {
liList[i].classList.toggle("done");
}
}
<ul>
<li>Notebook</li>
<li>Jello</li>
<li>Spinach</li>
<li>Rice</li>
<li>Birthday Cake</li>
<li>Candles</li>
</ul>