Loading…
Everything will be ready in few seconds
- Theory
- Theory
- Comments
Deleting the element from the list
The event is triggered. It is time to change the console output to remove the completed task.
There are various ways of removing elements from the page, of which one of the simplest is calling the remove
method on the element that needs to be removed.
element.remove();
The method in the example above removes the element
from DOM.
By the way, why did we use this function in particular and not add a handler to the element directly inside the loop? It all has to do with the scopes. We already discussed closures when we created the gallery in this chapter using events. If we placed the handler inside the loop, our program would not work correctly, because only the last element in the collection of elements would be deleted. If you forget why this behavior can happen, you can refresh your knowledge by first reviewing this assignment and then this one.
Use the remove
method to remove the completed task in our app.
- index.html
- style.css
- script.js
Thanks! We’ll fix everything at once!
Comments