diff --git a/ruty/js/scripttodo.js b/ruty/js/scripttodo.js index 2cded72..9e2e44c 100644 --- a/ruty/js/scripttodo.js +++ b/ruty/js/scripttodo.js @@ -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")) || [];