Skip to content

Commit

Permalink
Merge pull request #105 from piyushkdas0611/main
Browse files Browse the repository at this point in the history
added a clear all task button
  • Loading branch information
Kritika30032002 authored Oct 10, 2023
2 parents f40f0b0 + 020dae3 commit 275512d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ <h2 class="text-center mb-4">ADD ITEMS</h2>
/>
</form>

<button id="clearAllTasks" class="btn btn-danger clear_btn" onclick="clearAllTasks();">Clear All Tasks</button>

<div class="text-center">
<h3 class="mt-4 text-center" id="heading-tasks">Tasks</h3>

Expand Down
27 changes: 26 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ function addItem(e) {
if (newItem.trim() === "") return false;
else document.getElementById("item").value = "";

if(newItem.trim() !== "") {
document.querySelector(".clear_btn").style.display = "inline";
}

const li = document.createElement("li");
li.className = "list-group-item";

Expand Down Expand Up @@ -318,4 +322,25 @@ function toggleMode() {
path.style.fill = '#000'; // Change the fill color to black for light mode
});
}
}
}


function clearAllTasks() {

const ulElement = document.getElementById("items");


// Removes all tasks from the task list
while (ulElement.firstChild) {
ulElement.removeChild(ulElement.firstChild);
}

// Hide the button after the task list is cleared
document.querySelector(".clear_btn").style.display = "none";
console.log("task cleared");

// Hide the tasks heading since there are no tasks left

const tasksHeading = document.getElementById("heading-tasks");
tasksHeading.classList.add("hidden");
}
15 changes: 14 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,25 @@ body.dark-mode::before {
transition: opacity 0.3s;
}

.form_btn:hover {
.form_btn:hover, .clear_btn:hover{
opacity: 0.8;
outline: auto;
border: 3px solid rebeccapurple;
}

.clear_btn {
color: #fff;
letter-spacing: 0.11rem;
border: none;
background: linear-gradient(to right, rgb(225, 1, 1), rgb(236, 70, 70));
padding: 0.6rem 2rem;
border-radius: 5rem;
cursor: pointer;
transition: opacity 0.3s;
margin: 1rem 0;
display: none;
}

.opacity {
opacity: 0.8;
outline: auto;
Expand Down

0 comments on commit 275512d

Please sign in to comment.