-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (50 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//Selectors
const todoInput = document.querySelector('.todo-input');
const todoButton = document.querySelector('.todo-button');
const todoList = document.querySelector('.todo-list');
//Event Listeners
todoButton.addEventListener("click",addTodo);
todoList.addEventListener("click",deleteCheck);
//Functions
function addTodo(event){
//Prevent the default behaviour of form submitting.
event.preventDefault();
if(todoInput.value != ''){
const todoDiv = document.createElement('div');
todoDiv.classList.add('todo');
//create Li
const newTodo = document.createElement('li');
newTodo.classList.add('todo-item');
newTodo.innerText = todoInput.value;
todoDiv.appendChild(newTodo);
//Adding a checked icon
const checkedBtn = document.createElement('button');
checkedBtn.innerHTML = '<i class = "fas fa-check"></i>';
checkedBtn.classList.add('checked-btn');
todoDiv.appendChild(checkedBtn);
//Adding a removed icon
const removedBtn = document.createElement('button');
removedBtn.innerHTML = '<i class = "fas fa-trash"></i>';
removedBtn.classList.add('removed-btn');
todoDiv.appendChild(removedBtn);
todoList.appendChild(todoDiv);
}
else{
alert("No text added.");
}
todoInput.value = "";
}
function deleteCheck(event){
const item = event.target;
if(item.classList[0] === "removed-btn"){
const todo = item.parentElement;
todo.classList.add('jharyo');
todo.addEventListener("transitionend",()=>{
todo.remove();
})
}
if(item.classList[0] === "checked-btn"){
const todo = item.parentElement;
todo.classList.toggle('lineIt');
}
}