Search⌘ K
AI Features

Solution Review: Deleting a Task from the To-Do List

Understand how to implement task deletion in a to-do list by assigning dynamic click event handlers with jQuery's on() method. Learn to traverse the DOM to identify the correct task element and remove it using jQuery's remove() method for efficient manipulation.

We'll cover the following...

Solution

Explanation

  • In line 2, we assign a click event handler to the delete button, a descendant of div with id equal to delete. We use the on() method here because the delete button is dynamically created and the direct method $("#delete").click() won’t work.

  • In line 3, we extract the parent of the delete button, which is the task to be deleted.

  • In line 4, we delete that extracted parent element using the remove() method.