-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (39 loc) · 1.49 KB
/
script.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
const toDoItemsElem = document.getElementsByClassName('toDoItems')[0];
const inputElem = document.getElementById('userInput');
const trashIconElem = document.getElementById('trash');
inputElem.addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
addItem();
}
});
function addItem() {
let divParent = document.createElement('div');
let divChild = document.createElement('div');
let checkIcon = document.createElement('i');
let trashIcon = document.createElement('i');
divParent.className = 'item';
divParent.innerHTML = '<div>' + inputElem.value + '</div>';
checkIcon.className = 'fas fa-check-square';
checkIcon.style.color = 'lightgray';
checkIcon.addEventListener('click', function () {
if (checkIcon.style.color == 'limegreen') {
checkIcon.style.color = 'lightgray';
divParent.style.textDecoration = 'none';
divParent.style.color = '#454545';
} else {
checkIcon.style.color = 'limegreen';
divParent.style.textDecoration = 'line-through';
divParent.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);
toDoItemsElem.appendChild(divParent);
inputElem.value = '';
}