'Remove a class from list item of live collection/ HTMLCollection
I have created a to-do list, but after shifting a list item from ongoing to completed tab, the tick-mark button created using js is also shifted to completed tab.
I have coded in such a way that every list item created in ongoing tab is binded to tick-mark(class).To remove that button, we need to remove the class i.e. binded to list item.
I have tried:
var nextlist = document.getElementById("completed").getElementsByTagName("li");
var j;
for(j = 0; j < nextlist.length; j++){
nextlist[0].classList.remove("complete");
}
but it does not work. And because this is in HTMLCollection, we cannot use querySelectorAll()
Solution 1:[1]
You should replace nextlist[0] to nextlist[j]
var nextlist = document.getElementById("completed").getElementsByTagName("li");
var j;
for(j = 0; j < nextlist.length; j++){
nextlist[j].classList.remove("complete");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Georgy |
