-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (35 loc) · 1.26 KB
/
index.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
document.querySelector("#input").addEventListener("keydown", (event) => {
if(event.key === "Enter"){
const input = document.querySelector("#input");
addItem(input.value);
}
});
document.querySelector("#add_item").addEventListener("click", () => {
const input = document.querySelector("#input");
addItem(input.value);
});
addItem = (input) => {
const item = document.createElement("div");
const div = document.createElement("div");
const checkIcon = document.createElement("i");
const trashIcon = document.createElement("i");
const text = document.createElement("p");
item.className = "item";
text.textContent = input;
checkIcon.className = "fas fa-check-square";
checkIcon.style.color = "lightgray";
checkIcon.addEventListener("click", () => {
checkIcon.style.color = "limegreen";
})
div.appendChild(checkIcon);
trashIcon.className = "fas fa-trash";
trashIcon.style.color = "darkgray";
trashIcon.addEventListener("click", () => {
item.remove();
})
div.appendChild(trashIcon);
item.appendChild(text);
item.appendChild(div);
document.querySelector("#to_do_list").appendChild(item);
document.querySelector("#input").value = "";
}