ProjectsCore· 120 min read

Project: Interactive To-Do List

Bring it all together — variables, arrays, the DOM and events — to build a real, working to-do app.

What you will learn

  • Combine DOM, events and arrays
  • Add and remove items dynamically
  • Build a complete interactive feature

The brief

Build a to-do list where you can type a task, add it to the list, and remove it. No frameworks — just the JavaScript you now know.

Everything here is something you have already met: getElementById to grab elements, addEventListener for clicks, createElement/appendChild to build the page, and .remove() to delete. Read the code, then we will walk the whole flow.

A working to-do app
<input id="task" placeholder="What needs doing?">
<button id="add">Add</button>
<ul id="list"></ul>

<script>
  const input = document.getElementById("task");
  const list = document.getElementById("list");

  document.getElementById("add").addEventListener("click", function() {
    const text = input.value.trim();
    if (text === "") return;

    const li = document.createElement("li");
    li.textContent = text;

    const del = document.createElement("button");
    del.textContent = " ✕";
    del.addEventListener("click", () => li.remove());

    li.appendChild(del);
    list.appendChild(li);
    input.value = "";
  });
</script>
Live preview

Here is the full add-and-delete flow, step by step:

  1. We grab the text box (input) and the empty list (list) once at the top so we can reuse them.
  2. When Add is clicked, input.value.trim() reads what was typed and trims spaces.
  3. if (text === "") return guards against empty tasks — if the box is blank, we stop early and add nothing.
  4. createElement("li") makes a new list item and li.textContent = text puts the task words in it.
  5. We also build a small button, and give it its own click handler: () => li.remove() deletes that exact item.
  6. li.appendChild(del) puts the ✕ inside the item, then list.appendChild(li) adds the finished item to the page.
  7. Finally input.value = "" clears the box, ready for the next task.

Note: Output: Type "Buy milk" and click Add → a row "Buy milk ✕" appears. Type "Call Asha" and click Add → a second row appears below it. Click the ✕ on a row → just that row disappears.

Tip: Enhance it: mark tasks done on click (toggle a line-through style), save tasks in localStorage so they survive a refresh, or show a count of remaining tasks.

✍️ Practice

  1. Build the to-do app and confirm you can add and delete tasks.
  2. Add a “mark done” feature that toggles a line-through style.

🏠 Homework

  1. Save the to-do list in localStorage so the tasks remain after a page refresh.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →