-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (52 loc) · 1.65 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
53
54
55
56
const input = document.querySelector('.input-field')
const addBtn = document.querySelector('.btn.add')
const list = document.querySelector('.list')
const deleteBtn = document.querySelector('.btn.delete')
let tasks = []
const addTask = () => {
let newTask = ''
newTask = input.value
tasks.push(newTask)
let li = document.createElement('li')
list.appendChild(li)
const listContainer = document.createElement('div')
listContainer.classList.add('list-flex')
li.appendChild(listContainer)
const itemContainer = document.createElement('div')
itemContainer.classList.add('item')
listContainer.appendChild(itemContainer)
itemContainer.innerText = newTask
const btnContainer = document.createElement('div')
btnContainer.classList.add('btn-flex')
listContainer.appendChild(btnContainer)
const doneBtn = document.createElement('div')
doneBtn.classList.add('btn')
doneBtn.classList.add('done')
doneBtn.innerText = 'Done'
btnContainer.appendChild(doneBtn)
const deleteBtn = document.createElement('div')
deleteBtn.classList.add('btn')
deleteBtn.classList.add('delete')
deleteBtn.innerText = 'Delete'
btnContainer.appendChild(deleteBtn)
doneBtn.addEventListener('click', (e) => {
doneTask(e)
})
deleteBtn.addEventListener('click', (e) => {
deleteTask(e)
})
input.value = ''
}
addBtn.addEventListener('click', () => {
addTask()
})
const deleteTask = (e) => {
let newBtn = e.target
newBtn.parentElement.parentElement.parentElement.remove()
}
const doneTask = (e) => {
let checkContainer = e.target
const checkMark = document.createElement('div')
checkMark.classList.add('checked')
checkContainer.appendChild(checkMark)
}