Skip to content
Advertisement

Having an issue with deleting items in to do list project

I’m having an issue with the delete function. I’m at the point where I can remove only one line before pushing the submit button again. It seems that I can remove only the first paragraph that was submitted. It feels like eventListener applies only for the first line. Do I need a loop here?

Here is some of my code:

JavaScript
JavaScript

Advertisement

Answer

Use trashToDo.addEventListener instead of trashDelete.addEventListener. Also you do not need to get removeParent. Use divToDo.remove(); inside removeTask.

Issue with your code is due to document.getElementById('trash-delete'). getElementById will always find first element with id trash-delete. And you are assigning event to that first element only. So it always deletes first one for you.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement