Update scripttodo.js
This commit is contained in:
+17
-1
@@ -34,7 +34,12 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
const todoText = newTodoInput.value.trim();
|
||||
if (todoText !== "") {
|
||||
const todoItem = document.createElement("li");
|
||||
todoItem.textContent = todoText;
|
||||
const todoCheckbox = document.createElement("input");
|
||||
todoCheckbox.type = "checkbox";
|
||||
const todoSpan = document.createElement("span");
|
||||
todoSpan.textContent = todoText;
|
||||
todoItem.appendChild(todoCheckbox);
|
||||
todoItem.appendChild(todoSpan);
|
||||
todoList.appendChild(todoItem);
|
||||
newTodoInput.value = "";
|
||||
}
|
||||
@@ -60,6 +65,17 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
}
|
||||
});
|
||||
|
||||
todoList.addEventListener("change", function(event) {
|
||||
if (event.target.type === "checkbox") {
|
||||
const todoItem = event.target.parentNode;
|
||||
if (event.target.checked) {
|
||||
todoItem.classList.add("completed");
|
||||
} else {
|
||||
todoItem.classList.remove("completed");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Function to load existing todos from localStorage
|
||||
function loadTodos() {
|
||||
const savedTodos = JSON.parse(localStorage.getItem("todos")) || [];
|
||||
|
||||
Reference in New Issue
Block a user