-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (43 loc) · 1.33 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
let input = document.getElementById("myInput");
let button = document.getElementById("myBtn");
let ul = document.querySelector("ul");
function inputLength(){
return input.value.length;
}
function createListElement(){
let li = document.createElement("li");
li.appendChild(document.createTextNode(input.value));
ul.appendChild(li);
input.value = "";
function Completed(){
li.classList.toggle("done");
}
li.addEventListener("click", Completed);
let deleteButton = document.createElement("button");
deleteButton.appendChild(document.createTextNode("X"));
li.appendChild(deleteButton);
deleteButton.addEventListener("click", deleteListItem);
function deleteListItem(){
li.classList.add("delete");
}
}
function addListAfterClick(){
if (inputLength() > 0) {
createListElement();
}
}
function addListAfterEnter(event){
if (inputLength() > 0 && event.which === 13) {
createListElement();
}
}
input.addEventListener("keypress", addListAfterEnter);
button.addEventListener("click", addListAfterClick);
function clearList() {
let clearBtn = document.getElementsByTagName('li');
if (clearBtn.style.visibility === 'hidden') {
clearBtn.style.visibility = 'visible';
} else {
clearBtn.style.visibility = 'hidden';
}
}