-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (43 loc) · 1.45 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
const inputtdl = document.querySelector('.textarea');
const buttontdl = document.querySelector('.buttoninput');
const listtdl = document.querySelector('.todolist');
function clickButton(e) {
e.preventDefault()
addTodo()
}
//adding todo list
function addTodo() {
const itemall = document.createElement('div')
itemall.classList.add('itemall')
const item = document.createElement('p')
item.classList.add('item')
item.innerText = inputtdl.value
itemall.appendChild(item)
if (inputtdl.value === '') return
const checkbutton = document.createElement('button')
checkbutton.innerHTML = '<i class="fa-solid fa-check"></i>'
checkbutton.classList.add('check-button')
itemall.appendChild(checkbutton)
const trashbutton = document.createElement('button')
trashbutton.innerHTML = '<i class="fa-solid fa-trash"></i>'
trashbutton.classList.add('trash-button')
itemall.appendChild(trashbutton)
listtdl.appendChild(itemall)
inputtdl.value = ''
}
// checking and delete to do list
function okdel(e) {
const item = e.target
//check
if (item.classList[0] === 'check-button') {
const todolist = item.parentElement
todolist.classList.toggle('checklist')
}
//delete
if (item.classList[0] === 'trash-button') {
const todolist = item.parentElement
todolist.remove()
}
}
buttontdl.addEventListener('click', clickButton)
listtdl.addEventListener('click', okdel)