From 3eea39c208e77468d36996bd2b56520654fdb345 Mon Sep 17 00:00:00 2001 From: taqui-786 Date: Mon, 2 Oct 2023 12:21:17 +0530 Subject: [PATCH] Fixed Bug and Added New Feature --- index.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index cd26aa0..bec55ce 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ function markAsComplete(e) { function tasksCheck() { // This function checks if ul contains children or not. According to that it add or removes hidden class const tasksHeading = document.getElementById("heading-tasks"); - const ulElement = document.querySelector("#items"); + const ulElement = document.getElementById("items"); const children = ulElement.children; @@ -33,16 +33,17 @@ window.onload = () => { }; let editItem = null; + function addItem(e) { e.preventDefault(); if (submit.value !== "Submit") { - editItem.target.parentElement.childNodes[2].textContent = document.getElementById("item").value; + editItem.target.parentElement.childNodes[1].textContent = document.getElementById("item").value; submit.value = "Submit"; document.getElementById("item").value = ""; displaySuccessMessage("Text edited successfully"); - editItem = null; // Reset editItem after editing + editItem = null; return false; } tasksCheck() @@ -66,20 +67,32 @@ function addItem(e) { editButton.className = "btn btn-success btn-sm float-right edit"; editButton.appendChild(document.createTextNode("Edit")); editButton.style.marginRight = "8px"; + + // Create a click event listener for the edit button editButton.addEventListener("click", function (e) { - handleItemClick(e); + handleEditClick(e); }); + // Get the current date and time + const creationDateTime = new Date().toLocaleString(); + + // Create a paragraph element to display the creation date and time + const dateTimeParagraph = document.createElement("p"); + dateTimeParagraph.className = "text-muted"; + dateTimeParagraph.style.fontSize = "15px"; // Set font size + dateTimeParagraph.style.margin = "0 19px"; // Set margin + dateTimeParagraph.appendChild(document.createTextNode("Created: " + creationDateTime)); + li.appendChild(completeCheckbox); li.appendChild(document.createTextNode(newItem)); li.appendChild(deleteButton); li.appendChild(editButton); + li.appendChild(dateTimeParagraph); items.appendChild(li); - - } + function handleItemClick(e) { if (e.target.classList.contains("delete")) { const li = e.target.parentElement; @@ -88,12 +101,14 @@ function handleItemClick(e) { displaySuccessMessage("Text deleted successfully"); } if (e.target.classList.contains("edit")) { + e.preventDefault(); document.getElementById("item").value = e.target.parentElement.childNodes[1].textContent.trim(); submit.value = "EDIT"; editItem = e; } } + function toggleButton(ref, btnID) { document.getElementById(btnID).disabled = false; } @@ -105,4 +120,3 @@ function displaySuccessMessage(message) { document.getElementById("lblsuccess").style.display = "none"; }, 3000); } -