01 / 03
Multiple elements and event delegation
INPUT · Slides
Clear finished items in one go
02 / 03
The selector picks only the finished ones
document.querySelectorAll("#list li.is-done") returns only the li elements that have is-done.
.is-done is the class classList.toggle adds and removes. Only the rows where Done was pressed carry it.
const doneItems = document.querySelectorAll("#list li.is-done")console.log(doneItems.length) // number of finished rows03 / 03
Loop through and remove
Once you have them, for...of and remove() finish the job.
Put this together with the last step and the pattern is clear: select with a filter, then do something to all of them. That is the most general DOM pattern there is.
for (const item of doneItems) { item.remove()}