I've a bunch os <li>
and inside it I've a button that closes the li when clicked.
.forEach
does not work in index.js, but only in the Chrome console. I can conclude that the code is error free, so what the heck?
The HTML
<li draggable="true" class="draggable">
<input type="checkbox" name="" class="completed-input">
<input type="text" class="new-task-input" placeholder="your todo...">
<ion-icon name="close-outline"></ion-icon>
</li>
The JS
const btnsDelete = document.getElementsByName('close-outline')
btnsDeleteArray.forEach(btn => {
btn.addEventListener('click', e => {
containerAllTasks.removeChild(e.target.parentNode)
removeKeyByValue(e.target.parentNode.children[1].value)
countAllItems()
})
})
I tried to convert it to a usual Array instead a NodeList
const btnsDelete = document.getElementsByName('close-outline')
const btnsDeleteArray = Array.from(btnsDelete)
btnsDeleteArray.forEach(btn => {
btn.addEventListener('click', e => {
containerAllTasks.removeChild(e.target.parentNode)
removeKeyByValue(e.target.parentNode.children[1].value)
countAllItems()
})
})
I just want to run the code inside this forEach
every time a certain button is clicked