-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
77 lines (61 loc) · 2.26 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//DOM Elements
const forms = document.forms;
const list = document.querySelector(".tasks-list");
const completeList = document.querySelector(".completed-tasks-list");
//complete tasks
list.addEventListener("click", function(e){
if(e.target.className === "completeBtn"){
const li = e.target.parentElement.parentElement;
//Cloning list item
const clonedLi = li.cloneNode(true);
li.parentElement.removeChild(li);
//Appending list item into new list
completeList.appendChild(clonedLi);
//Adding new buttons and deleting old buttons
const deleteBtn = document.createElement("button");
deleteBtn.textContent="Delete Task";
clonedLi.appendChild(deleteBtn);
//Adding classes of complete-list and deleting classes of todo-list
deleteBtn.classList.add("deleteBtn");
clonedLi.classList.add("completed-tasks");
clonedLi.classList.remove("tasks")
////////// Still attempting to remove "completeBtn" from <li> when cloned to completed list
}
});
completeList.addEventListener("change", function(e){
if(e.element === "li"){
e.removeChild(completeBtnHandler)
}
})
//delete tasks from completed list
completeList.addEventListener("click", function(e){
if(e.target.className === "deleteBtn") {
const completedLi = e.target.parentElement;
completedLi.parentElement.removeChild(completedLi)
}
})
//add tasks
const addForm = forms["add-task-form"]
addForm.addEventListener("submit", function(e){
e.preventDefault();
//create elements
const value = addForm.querySelector('input[type="text"]').value;
const li = document.createElement("li");
const task = document.createElement("span");
const completeBtn = document.createElement("button");
//adding text content
task.textContent = value;
completeBtn.textContent = "Complete Task"
//appending new elements to DOM
li.appendChild(task);
li.appendChild(completeBtn);
list.appendChild(li);
//adding Classes
li.classList.add("tasks");
completeBtn.classList.add("completeBtn")
//Input bar becomes blank after submit
const resetInput = () => {
document.querySelector('input[type="text"]').value = "";
}
resetInput();
})