-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (30 loc) · 1.06 KB
/
index.js
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
33
34
document.querySelector("#push").onclick = function (){
if(document.querySelector("#newtask input").value.length == 0){
alert("Nothing was added! You gotta do something!")
}
else {
document.querySelector("#tasks").innerHTML += `
<div class="task">
<span id="taskname">
${document.querySelector('#newtask input').value}
</span>
<button class="delete">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
</div>
`;
const currentTask = document.querySelectorAll(".delete");
for(let i = 0; i < currentTask.length; i++) {
currentTask[i].onclick = function() {
this.parentNode.remove();
}
}
const tasks = document.querySelectorAll(".task");
for(let i = 0; i < tasks.length; i++){
tasks[i].onclick = function() {
this.classList.toggle('completed')
}
}
document.querySelector("#newtask input").value = "";
}
}