-
Notifications
You must be signed in to change notification settings - Fork 0
/
To-do_List.js
56 lines (36 loc) · 1.21 KB
/
To-do_List.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
let input = document.getElementById("list")
let indList = document.getElementById("indList")
let btn = document.getElementById("btn")
let clearBtn = document.getElementById("clearbtn")
function addActivityToList() {
if (input.value.length > 0) {
create() // to make sure an empty list isnt added
}
function create() {
let li = document.createElement("p");
let rembtn = document.createElement("button");
rembtn.append("Remove");
li.append(document.createTextNode(input.value), rembtn);//Add the li and rembtn
indList.appendChild(li);
input.value = ""; // reset input
//Highlighting the completed task
function highlight() {
li.style.backgroundColor = "#51DF70"
li.style.color = "#00891E"
}
li.addEventListener("click", highlight)
//Removing the item from list
rembtn.addEventListener("click", () => {
li.remove()
})
//Clear all items
clearBtn.addEventListener("click", () => { li.remove() })
}
}
function pressEnter() {
if (event.which === 13) { //this now looks to see if you hit "enter"/"return"
addActivityToList();
}
}
input.addEventListener("keypress", pressEnter);
btn.addEventListener("click", addActivityToList)