I started learning JavaScript by following a video guide. I recently ran into a problem while trying to complete an assignment from the video.
I created a list of items that you can add to or remove from by taking user inputs. You should also be able to click on an item to strike it out. It is expected that when you click on an element with strikethrough, the line should disappear. This is a toggle function.
I have figured out all the other parts except this last one.
When I use querySelector, it chooses only the first element which is fine. However, when I use querySelectorAll, nothing happens and Javascript console on Chrome returns the following:
Uncaught TypeError: items.addEventListener is not a function
Here is what I have tried:
var items = document.querySelectorAll("li");
function toggleOnOff() {
items.classList.toggle("done");
}
items.addEventListener("click", toggleOnOff);
I want to be able to toggle on/off any item on the list using the css strikethrough class that I have created.