-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (30 loc) · 1.1 KB
/
script.js
File metadata and controls
43 lines (30 loc) · 1.1 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
40
41
const toDoItems = document.getElementsByClassName("to-do-items")[0];
const input=document.getElementById("input");
const trashIcon=document.getElementById("trash");
input.addEventListener("keydown", function(event){
if(event.key === "Enter")
addItem();
})
function addItem(){
var divParent =document.createElement("div");
var divChild =document.createElement("div");
var checkIcon =document.createElement("i");
var trashIcon =document.createElement("i");
divParent.className = "item";
divParent.innerHTML = '<div>'+input.value+'</div>';
checkIcon.className = "fas fa-check-square";
checkIcon.style.color = "lightgray";
checkIcon.addEventListener("click", function(){
checkIcon.style.color = "limegreen";
})
divChild.appendChild(checkIcon);
trashIcon.className = "fas fa-trash";
trashIcon.style.color = "darkgray";
trashIcon.addEventListener("click", function(){
divParent.remove();
})
divChild.appendChild(trashIcon);
divParent.appendChild(divChild);
toDoItems.appendChild(divParent);
input.value = '';
}