forked from Yashu1th/ToDoList
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (30 loc) · 1.04 KB
/
script.js
File metadata and controls
32 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
document.querySelector;
document.querySelector("#push").onclick=function(){
if(document.querySelector("#new_task input").value.length==0){
alert("Please enter the task");
}
else{
document.querySelector(".tasks").innerHTML
+=`
<div class="task">
<span id="taskName">${document.querySelector("#new_task input").value}</span>
<button class="delete">
<i class="fa-solid fa-trash"></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("#new_task input").value="";
}
}