Aral Code

Going Further Lesson 10 of 10

jQuery Final Project — A Class To-Do App

Build a complete to-do app with jQuery — add, complete, edit and delete tasks, filter them, show counts, use event delegation and effects — plus how to save tasks with localStorage.

Let's combine selectors, events, delegation, DOM changes, traversing and effects into one useful app: a to-do list for school tasks, with subjects, filters and counts.

Features

  • Add a task with a subject tag.
  • Click a task to mark it done; double-click to edit; ✕ to delete.
  • Filter: all, active, done.
  • A live count of tasks left.

The app

Example School To-Do App
<script src="/vendor/jquery.min.js"></script>
<style>
  body { font-family: system-ui, sans-serif; background: #f3f6f4; margin: 0; }
  .app { max-width: 460px; margin: 16px auto; background: white; border-radius: 16px; padding: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.07); }
  form { display: flex; gap: 6px; }
  input, select, button { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid #ccd3cf; }
  input { flex: 1; }
  button { background: #0f5c4d; color: white; border: 0; cursor: pointer; }
  ul { list-style: none; padding: 0; }
  li { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid #eee; cursor: pointer; }
  li .text { flex: 1; }
  li.done .text { text-decoration: line-through; opacity: .5; }
  .tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #e3f1ec; color: #0f5c4d; }
  .del { background: none; color: #b4372b; padding: 2px 6px; }
  .filters button { background: #eef2f0; color: #333; }
  .filters button.on { background: #0f5c4d; color: #fff; }
  .bar { display: flex; justify-content: space-between; align-items: center; color: #5b6662; font-size: 14px; }
</style>
<div class="app">
  <h2>📝 Mga Gagawin</h2>
  <form id="add">
    <input id="text" placeholder="New task, e.g. Research paper" autocomplete="off">
    <select id="subject"><option>Math</option><option>Science</option><option>English</option><option>ICT</option></select>
    <button>Add</button>
  </form>
  <ul id="list"></ul>
  <div class="bar">
    <span id="left"></span>
    <span class="filters">
      <button data-filter="all" class="on">All</button>
      <button data-filter="active">Active</button>
      <button data-filter="done">Done</button>
    </span>
  </div>
</div>
<script>
  $(function () {
    let filter = "all";

    function addTask(text, subject, done) {
      const li = $("<li>").toggleClass("done", !!done);
      li.append($("<span class='tag'>").text(subject));
      li.append($("<span class='text'>").text(text));
      li.append($("<button class='del' title='Delete'>✕</button>"));
      li.hide().appendTo("#list").fadeIn(200);
    }

    function refresh() {
      $("#list li").each(function () {
        const done = $(this).hasClass("done");
        const show = filter === "all" || (filter === "done" ? done : !done);
        $(this).toggle(show);
      });
      const left = $("#list li").not(".done").length;
      $("#left").text(left + (left === 1 ? " task left" : " tasks left"));
    }

    // Add
    $("#add").on("submit", function (e) {
      e.preventDefault();
      const text = $("#text").val().trim();
      if (!text) return $("#text").focus();
      addTask(text, $("#subject").val(), false);
      $("#text").val("").focus();
      refresh();
    });

    // Toggle done (delegated, works for new tasks too)
    $("#list").on("click", "li", function (e) {
      if ($(e.target).is(".del, input")) return;
      $(this).toggleClass("done");
      refresh();
    });

    // Delete
    $("#list").on("click", ".del", function () {
      $(this).closest("li").fadeOut(200, function () {
        $(this).remove();
        refresh();
      });
    });

    // Edit on double-click
    $("#list").on("dblclick", ".text", function () {
      const span = $(this);
      const input = $("<input>").val(span.text());
      span.replaceWith(input);
      input.focus().on("blur keydown", function (e) {
        if (e.type === "keydown" && e.key !== "Enter") return;
        const value = input.val().trim() || span.text();
        input.replaceWith(span.text(value));
      });
    });

    // Filters
    $(".filters").on("click", "button", function () {
      $(this).addClass("on").siblings().removeClass("on");
      filter = $(this).data("filter");
      refresh();
    });

    // Starter tasks
    addTask("Answer module 3", "Math", false);
    addTask("Lab report", "Science", true);
    refresh();
  });
</script>

How it works

PartjQuery skills
addTaskCreating elements with $("<li>"), .text() for safe content, .fadeIn()
Toggle, delete, editEvent delegation on #list, closest, replaceWith
refresh.each(), .toggle(show), .not(".done").length
Filtersdata-filter with .data(), .siblings()

The task text is always set with .text(), so a task like <b>hi</b> shows literally instead of becoming HTML.

Saving tasks with localStorage

To keep tasks after closing the browser, save them as JSON whenever something changes, and load them on start. (The Try-it editor blocks storage; this works when you save the page as an .html file.)

function save() {
  const tasks = $("#list li").map(function () {
    return {
      text: $(this).find(".text").text(),
      subject: $(this).find(".tag").text(),
      done: $(this).hasClass("done")
    };
  }).get();
  localStorage.setItem("tasks", JSON.stringify(tasks));
}

function load() {
  const tasks = JSON.parse(localStorage.getItem("tasks") || "[]");
  tasks.forEach((t) => addTask(t.text, t.subject, t.done));
}

Call save() at the end of refresh(), and load() instead of adding the starter tasks.

Challenges

  1. Add a due date to each task and sort by it.
  2. Add a "Clear done" button.
  3. Show a count per subject.
  4. Rebuild the same app in plain JavaScript or React, and compare the code.

What's next?

Congratulations on finishing the jQuery course! 🎉 You can now read and improve jQuery code on existing sites. For new projects, continue with modern JavaScript and React.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Why are the click handlers attached to #list instead of each li?
2. Why is the task text set with .text()?
3. What does $("#list li").not(".done").length count?
4. What does .toggle(show) do with a true/false argument?

By Sir Reyel · Last updated 2026-12-04