-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopping.js
50 lines (43 loc) · 1.14 KB
/
shopping.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
var button = document.getElementById("enter")
var textarea = document.getElementById("userinput")
var ul = document.querySelector("ul")
function click(){
if(textarea.value.length>0){
createListelement()
}
}
function press(event){
if(textarea.value.length>0 && event.code === "Enter"){
createListelement()
}
}
function createListelement(){
var div = document.createElement("div")
var li = document.createElement("li")
var delbutton = document.createElement("button")
div.classList.add("wrapper")
li.appendChild(document.createTextNode(textarea.value))
ul.appendChild(div)
div.append(li, delbutton)
li.classList.add("taskclass")
delbutton.classList.add("delclass")
textarea.value =""
delbutton.innerHTML ="clear";
}
function dellist(element){
if (element.target.className === "delclass"){
element.target.parentElement.remove();
}
}
function donetask(e) {
if (e.target.tagName === "LI"){
e.target.classList.toggle("cross");
}
}
function handleulclick(element){
donetask(element);
dellist(element);
}
ul.addEventListener("click",handleulclick)
button.addEventListener("click",click)
textarea.addEventListener("keypress", press)