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 List

My if Statement does not work which is supposed to delete an item when the cross is clicked

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->
  <link href="style.css" rel="stylesheet">
  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">

  <title>To Do List</title>

</head>
<body>
  <header>
    <h1>ToDo</h1>

    <img src='images/icon-sun.svg' alt="sun for light mode" id="sun">

    <form>
      <input type="text" placeholder="Create a new todo..." name="listItem" id='create'></input>


  </header>

<ul id='list'></ul>
<!-- <img src="images/icon-cross.svg" alt='cross to delete list item'> -->
</form>

  <div class="buttons">
<button>All</button>
<button>Active</button>
<button>Completed</button>
</div>
 <button id="clear">Clear</button>



  <div class="attribution">
   Coded by <a href="#">Muaaz Matwadia</a>.
  </div>
  <script src="script.js"></script>
</body>
</html>
}

```js{
const form = document.querySelector('form');
const input = document.querySelector('input');
const ul = document.getElementById('list');
const clear =document.getElementById('clear');

input.focus()

form.addEventListener('submit' , (e) =>{
    e.preventDefault()
   let newItem = input.value;
   const li = document.createElement('li');
   li.textContent = newItem ;
   ul.appendChild(li);
   input.value = '';
   const check = document.createElement('input');
   check.type = 'checkbox';
   check.className = "checkboxes";
   ul.appendChild(check);
   const liImg = document.createElement('img') ;
   liImg.src = 'images/icon-cross.svg';
   ul.appendChild(liImg);
  console.log(e.target)

  if(e.target === liImg){
    li.remove();
    liImg.remove()
  }


});
}