-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
70 lines (61 loc) · 1.81 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
var button = document.getElementById("enter");
var input = document.getElementById("userinput");
var ul = document.querySelector("ul");
function len() {
return input.value.length;
}
function createElement() {
var li = document.createElement("li");
li.classList.add("item");
li.appendChild(document.createTextNode(input.value));
var li2 = document.createElement("li");
li2.classList.add("item1");
li.appendChild(li2);
var c = document.createElement("button");
c.appendChild(document.createTextNode("✔"));
c.classList.add("cros");
li2.appendChild(c);
var b = document.createElement("button");
b.appendChild(document.createTextNode("❌"));
b.classList.add("del");
li2.appendChild(b);
ul.appendChild(li);
input.value = "";
b.onclick = removeparnt;
c.onclick = crossout;
}
function afterClick() {
if (len() > 0) {
createElement();
}
}
function afterKeypress(event) {
if (len() > 0 && event.keyCode === 13) {
createElement();
}
}
button.addEventListener("click", afterClick);
input.addEventListener("keypress", afterKeypress);
var item = document.getElementsByClassName("cros");
var noitems = item.length;
for (var i = 0; i < noitems; i++) {
item[i].addEventListener("click", crossout);
}
var cross = document.getElementsByClassName("del");
var nocross = cross.length;
for (var i = 0; i < nocross; i++) {
cross[i].addEventListener("click", removeparnt);
}
function removeparnt(event) {
event.target.parentNode.parentNode.remove();
}
function crossout(event) {
event.target.parentNode.parentNode.classList.toggle("done");
}
var bgcolor = document.querySelector("#colorid");
var nic = document.querySelector("#nid");
var body = document.querySelector("body");
bgcolor.addEventListener("input", function () {
body.style.background = bgcolor.value;
nic.style.color = bgcolor.value;
});