Issues with Javascript To-Do list: Deleting Tasks and Local Storage

I’m working on a simple to-do list application using HTML, CSS and Javascript. I’ve encountered an issue when trying to delete tasks from the task list. I’m trying to implement a feature where clicking on the delete button removes the corresponding task item from the list but it’s not working as expected. The delete button appears correctly, but when clicked it does not remove the task item from the list. I’ve also implemented the functionality to store the tasks i the local storage so that they can persist even after the page has been refreshed but this doesn’t seem to be working either. When I refresh the page, the tasks are not refreshed from the local storage.

This is my Javascript code.

const taskInput = document.getElementById("taskInput");
const taskForm = document.getElementById("taskForm");
const appContainer = document.querySelector(".todo-app");
taskForm.addEventListener("submit", function (event) {
  event.preventDefault();
});

function addTask() {
  if (taskInput.value === "") {
    alert("Please input a task!");
  } else {
    let tasksWrapper = document.createElement("div");
    tasksWrapper.className = "tasks-wrapper";

    let taskItem = document.createElement("div");
    taskItem.className = "task-item";
    tasksWrapper.appendChild(taskItem);

    let checkboxContainer = document.createElement("div");
    checkboxContainer.className = "checkbox-container";
    taskItem.appendChild(checkboxContainer);

    let checkBox = document.createElement("input");
    checkBox.type = "checkbox";
    checkBox.onclick = function () {
      if (checkBox.checked) {
        taskText.classList.add("checked");
      } else {
        taskText.classList.remove("checked");
      }
    };
    checkboxContainer.appendChild(checkBox);

    let taskText = document.createElement("span");
    taskText.innerHTML = taskInput.value;
    taskItem.appendChild(taskText);

    let controlButtons = document.createElement("div");
    controlButtons.className = "controls";
    taskItem.appendChild(controlButtons);

    let editButton = document.createElement("button");
    editButton.innerHTML = '<i class="fa-regular fa-pen-to-square"></i>';
    editButton.className = "edit-button";
    editButton.onclick = function () {
      taskText.contentEditable = true;
    //   taskText.focus();
    };
    controlButtons.appendChild(editButton);

    taskText.onblur = function () {
      taskText.contentEditable = false;
    };

    let deleteButton = document.createElement("button");
    deleteButton.innerHTML = '<i class="fa-regular fa-trash-can"></i>';
    deleteButton.className = "delete-button";
    deleteButton.onclick = function () {
      taskForm.removeChild(tasksWrapper);
    };

    controlButtons.appendChild(deleteButton);

    appContainer.appendChild(tasksWrapper);
  }

  taskInput.value = "";
}

function saveData() {
  localStorage.setItem("data", tasksWrapper.innerHTML);
}

function showTask() {
  tasksWrapper.innerHTML = localStorage.getItem("data");
}
saveData();
showTask();

I’ve tried debugging the code and reviewing similar questions but I’m still not able to identify error causing this. Could someone please review my code and provide guidance on how to resolve this issues with deleting tasks and saving to local storage.
Thanks in advance.

New contributor

Zoe Yahmi Darlington is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật