-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
47 lines (41 loc) · 1.28 KB
/
script.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
35
36
37
38
39
40
41
42
43
44
45
46
47
const form = document.querySelector('#toDoForm')
const list = document.querySelector('#toDoList')
form.addEventListener("submit", (e) => {
e.preventDefault();
const taskInput = form.elements.task;
if(!taskInput.value){
alert("Opps, there is nothing to do. Please enter some task.")
} else {
addTask(taskInput.value)
};
taskInput.value = "";
})
const addTask = (task) => {
const div = document.createElement('div');
// Create new task
const newTask = document.createElement('li');
div.append(newTask);
newTask.append(task);
// Done button for every task
const doneBut = document.createElement('button');
doneBut.innerHTML = "<i class='fas fa-check'></i>";
doneBut.classList.add('done-btn');
doneBut.addEventListener('click', doneTask);
div.appendChild(doneBut);
// Delete button for every task
const delBut = document.createElement('button');
delBut.innerHTML = "<i class='fas fa-trash'></i>";
delBut.classList.add('del-btn');
delBut.addEventListener('click', delTask);
div.appendChild(delBut);
// Append div to ul
list.append(div);
}
function delTask() {
let li = this.parentNode;
li.remove();
}
function doneTask() {
let li = this.parentNode;
li.classList.add('done');
}