-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (59 loc) · 1.97 KB
/
Copy pathscript.js
File metadata and controls
71 lines (59 loc) · 1.97 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// JS for shopping list.
let button = document.getElementById("enter");
let input = document.getElementById("userinput");
let ul = document.querySelector("ul");
let list = document.querySelectorAll("li");
function inputLength(){
return input.value.length;
}
function createListElement(){
let li = document.createElement("li");
li.appendChild(document.createTextNode(input.value));
ul.appendChild(li);
input.value ="";
let btns = document.createElement("button");
btns.appendChild(document.createTextNode("Delite"));
li.append(btns);
btns.addEventListener("click", function(){
this.parentNode.remove();
})
li.addEventListener("click", function(){
this.classList.toggle("done");
})
}
for (let i=0; i < list.length; i++){
list[i].addEventListener("click", function(){
this.classList.toggle("done");
});
}
for(let i=0; i < list.length; i++){
let btn = document.createElement("button");
btn.appendChild(document.createTextNode("Delete"));
list[i].append(btn);
btn.addEventListener("click", function(){
this.parentNode.remove();
})
}
function addEventClick(){
if (inputLength() > 0){
createListElement();
}
}
function addEventKeypress(press){
if(inputLength() > 0 && press.keyCode === 13){
createListElement();
}
}
button.addEventListener("click", addEventClick);
input.addEventListener("keypress", addEventKeypress);
// JS for gradient background generator.
let css = document.querySelector("h3");
let color1 = document.querySelector(".color1");
let color2 = document.querySelector(".color2");
let body = document.getElementById("gradient");
function addGradient(){
body.style.background = "linear-gradient(to right, " + color1.value + ", " + color2.value + ")";
css.textContent = body.style.background + "; - "+ color1.value + ", " + color2.value + ". ";
}
color1.addEventListener("input", addGradient);
color2.addEventListener("input", addGradient);