Need some assistance with this: I've been working on an advanced to-do list for practice using JS, but I'm encountering an issue when trying to remove items from the list. When there are only two items left, and I try to remove the second one, the click event runs twice. However, the code works fine - I just get an error because the click event runs twice. This also happens when there's only one item left, but when I have more than 2 items and try to remove them, the event runs as expected. Another detail I'd like to mention is that inside a button, I've added an SVG that triggers this double-click event.
hiqBtn.addEventListener('click',()=>{
let arrPerMinus = []; //elements pushed to this array
arrPerMinus.forEach(el => { //adding event listener for each element
el.addEventListener('click',e =>{//**Also worth noting that these elements are SVGs**
//code executed here
})
})
}
I'm hoping to resolve the issue of the double-click event while ensuring that the code continues to function correctly.