-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (38 loc) · 1.48 KB
/
app.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
let taskTextInput = document.querySelector('.create-new-todo-form__input')
let addTaskButton = document.querySelector('.create-new-todo-form__button')
let todoList = document.querySelector('.task-table')
addTaskButton.addEventListener('click', addToDo)
function addToDo (e) {
e.preventDefault()
let inputValue = taskTextInput.value
let todoTask = document.createElement('li');
todoTask.classList.add('task')
let taskText = document.createElement('span')
taskText.classList.add('task__text')
taskText.innerHTML = inputValue
todoTask.append(taskText)
todoList.append(todoTask);
let buttonWrapper = document.createElement('div')
todoTask.append(buttonWrapper)
let checkButton = createButtons('fa-check')
let trashButton = createButtons('fa-trash-alt')
buttonWrapper.append(checkButton)
buttonWrapper.append(trashButton)
checkButton.addEventListener('click', () => {
todoTask.classList.toggle('completed')
checkButton.classList.toggle('completed')
})
trashButton.addEventListener('click', () => {
todoTask.remove();
})
taskTextInput.value = ''
function createButtons (imgType) {
let createButton = document.createElement('button')
createButton.classList.add('task__button')
buttonImg = document.createElement('i')
buttonImg.classList.add('fas')
buttonImg.classList.add(imgType)
createButton.append(buttonImg)
return createButton
}
}