Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
YOGINIMAHIMA1 authored Jan 2, 2024
1 parent e49056a commit a4f4475
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions TASK2(TODOLIST APP/script.js
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
document.querySelector('#push').onclick = function(){
if(document.querySelector('#newtask input').value.length == 0){
alert("Please Enter a Task")
}
else{
document.querySelector('#tasks').innerHTML += `
<div class="task">
<span id="taskname">
${document.querySelector('#newtask input').value}
</span>
<button class="delete">
<i class="far fa-trash-alt"></i>
</button>
</div>
`;

var current_tasks = document.querySelectorAll(".delete");
for(var i=0; i<current_tasks.length; i++){
current_tasks[i].onclick = function(){
this.parentNode.remove();
}
}

var tasks = document.querySelectorAll(".task");
for(var i=0; i<tasks.length; i++){
tasks[i].onclick = function(){
this.classList.toggle('completed');
}
}

document.querySelector("#newtask input").value = "";
}
}

0 comments on commit a4f4475

Please sign in to comment.