Hello everyone, I have a very simple question I couldn’t find the exact answer to on google.
list.addEventListener('click', e => {
if(e.target.classList.contains('delete'))
e.target.parentElement.remove();
});
How do I add a setTimeout property to this? Whenever I do I end up breaking the function completely. I need a more experienced developer’s advice/
Thank you in advance.
Hello!
You’re trying to add a delay to the removal of the parent element, right? If so, then this should work:
list.addEventListener('click', e => {
if (e.target.classList.contains('delete')) {
const handle = setTimeout(() => {
e.target.parentElement.remove();
clearTimeout(handle);
}, 1000);
}
});
This would remove the parent element after 1 second (1000 milliseconds).
Hope it helps
.
Yes this is exactly what I wanted. I see what I was doing wrong now, thank you.