-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
79 lines (48 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function onReady(){
const addToDoForm = document.getElementById("addToDoForm");
const newToDoText = document.getElementById("newToDoText");
const toDoList = document.getElementById("toDoList");
const deleteToDo= document.getElementById('deleteToDo');
addToDoForm.addEventListener("submit", (event) => {
event.preventDefault();
//get the text
let title = newToDoText.value;
//create a new li
let newLi = document.createElement('li');
//create a new input for the checkbox
let checkbox = document.createElement("input");
//set the input's type to checkbox
checkbox.type ="checkbox";
//set the title
newLi.textContent = title;
toDoList.appendChild(newLi);
//attach the ceckbox to the li
newLi.appendChild(checkbox);
//empty input
newToDoText.value="";
});
deleteToDo.addEventListener('click' , deleteList );
}
function deleteList(event){
event.preventDefault();
//Goal:delete checked items
// When a button is clicked go over all li elements
const deleteToDoForm = document.querySelector('#toDoList');
// event.preventDefault();
const listItems = deleteToDoForm.querySelectorAll ('li');
// loop over all elements
for (var i=0 ; i < listItems.length ; i++){
let currentLi = listItems[i];
let checkbox= currentLi.querySelector('input[type="checkbox"]');
//check for li elements
//check to see if box is checked
if(checkbox.checked ===true){
//if box is checked identifiy element
//delete elements that are identified as checked
deleteToDoForm.removeChild(currentLi);
}
}
}
window.onload = function(){
onReady();
};