-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (42 loc) · 1.21 KB
/
Copy pathscript.js
File metadata and controls
57 lines (42 loc) · 1.21 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
42
43
44
45
46
47
48
49
50
51
52
53
var button = document.getElementById("enter");
var input = document.getElementById("userinput");
var ul = document.querySelector("ul");
function inputLength() {
return input.value.length;
}
function createListElement() {
var btn = document.createElement("BUTTON");
btn.name = "Remove";
btn.className = "frame";
btn.appendChild(document.createTextNode("Remove"));
var li = document.createElement("li");
li.appendChild(document.createTextNode(input.value));
ul.appendChild(li);
ul.appendChild(btn);
input.value = "";
}
function addListAfterClick() {
if (inputLength() > 0) {
createListElement();
}
}
function addListAfterKeypress(event) {
if (inputLength() > 0 && event.keyCode === 13) {
createListElement();
}
}
button.addEventListener("click", addListAfterClick);
input.addEventListener("keypress", addListAfterKeypress);
//This is done by me
document.addEventListener('click',function(event){
var check = event.target;
if (check.tagName === "LI") {
check.classList.toggle("done");
}
else if(event.target.name ==="Remove"){
var target = event.target.previousElementSibling;
var button = event.srcElement;
button.parentNode.removeChild(button);
target.parentNode.removeChild(target);
}
});