What is causing this error?

https://glistening-bombolone-928636.netlify.app/ After you start removing selected filters an error pops up in the console about line of code that removes them, but everything works. I ignored it since it works, but it is bugging me and would like to know how to fix it. Cheers!
4 Replies
MarkBoots
MarkBoots2y ago
can you try, instead of
removeFilter[i].addEventListener('click', () => {
selectedFilters.removeChild(selectedFilterUnit[i]);
//...
})
removeFilter[i].addEventListener('click', () => {
selectedFilters.removeChild(selectedFilterUnit[i]);
//...
})
removeFilter[i].addEventListener('click', ({currentTarget}) => {
currentTarget.remove();
//....
})
removeFilter[i].addEventListener('click', ({currentTarget}) => {
currentTarget.remove();
//....
})
Dovah
DovahOP2y ago
@MarkBoots So since the filter is consisted of filter name and button, and I'm targeting button here, it only removes button. But If I add
currentTarget.closest('div').remove();
currentTarget.closest('div').remove();
it works
MarkBoots
MarkBoots2y ago
ah okay, i overlooked the difference in removeFilter[i] and selectedFilterUnit[i]. thought it was the same element btw, with this it is easy to make a named callback function (makes it a lot cleaner so you don't have a huge codeblock)
removeFilter[i].addEventListener('click', handleFilterRemove)


function handleFilterRemove({currentTarget}){
currentTarget.closest('div').remove();
}
removeFilter[i].addEventListener('click', handleFilterRemove)


function handleFilterRemove({currentTarget}){
currentTarget.closest('div').remove();
}
Dovah
DovahOP2y ago
Roger! Thanks a lot!
Want results from more Discord servers?
Add your server