-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (63 loc) · 1.82 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Element Selectors
var button = document.getElementById("enter");
var input = document.getElementById("userinput");
var ul = document.querySelector("ul");
var li = document.querySelector("li");
// Functions
function inputLength() {
return input.value.length;
}
function createListElement() {
var li = document.createElement('li');
li.appendChild(document.createTextNode(input.value));
ul.appendChild(li);
input.value = '';
var button = document.createElement('button');
button.appendChild(document.createTextNode("Delete!"));
li.appendChild(button);
button.onclick = removeParent;
}
function addListAfterClick() {
if(inputLength() > 0){
createListElement();
}
}
function addListAfterKeypress(event) {
if(inputLength() > 0 && event.keyCode === 13){
createListElement();
}
}
// Event Listeners
button.addEventListener('click', addListAfterClick);
input.addEventListener('keypress', addListAfterKeypress);
// ul.addEventListener('click', function(event){
// event.target.classList.toggle('done');
// });
// GO THRU THIS CODE WHEN YOU CAN !!!!
// GO THRU THIS CODE WHEN YOU CAN !!!!
// GO THRU THIS CODE WHEN YOU CAN !!!!
// document.querySelector('ul').addEventListener('click', function(event){
// event.target.classList.toggle("done")
// })
// document.querySelector('ul').onclick = function(event){
// event.target.classList.toggle("done")
// }
ul.onclick = function(event){
var target=event.target;
target.classList.toggle("done");
}
function listLength(){
return li.length;
}
function deleteButton(){
var btn=document.createElement("button");
btn.appendChild(document.createTextNode("Delete!"));
li[i].appendChild(btn);
btn.onclick=removeParent;
}
for( i=0;i<listLength();i++){
deleteButton();
}
function removeParent(evt){
evt.target.parentNode.remove();
}