Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

To Do App Question

This is from the to do app intermediate course done with JS only. The pen can be viewed here: http://codepen.io/bluehabit/pen/adBEjr

My question is what within the code is specifically targeting the edit and delete buttons for the tasks? The other buttons are stored within variables for instance:

var taskInput = document.getElementById('new-task');//new-task
var addButton = document.getElementsByTagName('button')[0]; //first button 'add'

These variables are then later used in functions.

However, with the edit and delete buttons, I do not see any variables, all I see are functions such as:

var deleteTask = function() {
  console.log("Delete task...");
  var listItem = this.parentNode;
  var ul = listItem.parentNode;

  //Remove the parent list item from the ul
  ul.removeChild(listItem);
}

How is this program specifically targeting the edit and delete buttons?

1 Answer

If you look at line 126 in your CodePen code, you wrote

 deleteButton.onclick = deleteTask;

which hooks the deleteTask function to the deleteButton, so the code inside deleteTask will run when the deleteButton is clicked.