This commit is contained in:
2024-12-31 00:12:59 +00:00
parent c6d68334be
commit ecd7b650bd
4 changed files with 151 additions and 115 deletions

View File

@@ -0,0 +1,24 @@
// Function to delete a todo item
function deleteTodo(todo) {
fetch("/todo", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ todo }),
})
.then((response) => {
if (response.ok) {
// Remove the list item and button from the DOM
const listItem = [...document.querySelectorAll("li")].find((li) =>
li.textContent.trim().startsWith(todo)
);
if (listItem) {
listItem.remove();
}
} else {
console.error("Failed to delete the todo item.");
}
})
.catch((error) => console.error("Error deleting todo:", error));
}