-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject_toDolist.js
More file actions
41 lines (31 loc) · 1.16 KB
/
project_toDolist.js
File metadata and controls
41 lines (31 loc) · 1.16 KB
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
const form=document.querySelector('.formList');
const todoform = document.querySelector('.formList input[type="text"]');
const todoSubmit = document.querySelector('.formList input[type="submit"]')
const parent = todoform.parentElement.nextElementSibling;
console.log(parent);
const removeBtn=document.querySelector('.remove')
console.log(removeBtn);
form.addEventListener('submit', (e) => {
e.preventDefault();
let newliText= todoform.value;
let newli = document.createElement('li');
todoform.value="";
newli.innerHTML = `<span class="text">${newliText}</span>
<div class="todo-buttons">
<button class="todo-btn done">Done</button>
<button class="todo-btn remove">Remove</button>
</div>`;
parent.append(newli);
let doneBtn=todoform.parentElement
console.log(doneBtn);
})
parent.addEventListener('click',function (e){
if(e.target.classList.contains('done')){
const goals=e.target.parentElement.previousElementSibling;
goals.style.textDecoration='line-through';
}
else if(e.target.classList.contains('remove')){
const goals=e.target.parentElement.parentElement;
goals.remove();
}
})