-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (62 loc) · 2.12 KB
/
index.js
File metadata and controls
73 lines (62 loc) · 2.12 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
72
73
var par = document.querySelector(".parent");
var btn = document.querySelector(".add");
var input = document.querySelector(".input");
var clear = document.querySelector(".clear");
btn.addEventListener("click",()=>{
toDo();
});
document.addEventListener("keypress",(e)=>{
if(e.key==="Enter"){
toDo();
}
});
function toDo(){
if(input.value===""){
return;
}
var abox = document.createElement("div");
var content = document.createElement("div");
var text = document.createElement("input");
var del = document.createElement("button");
var edit = document.createElement("button");
var actions = document.createElement("div");
text.type="text";
text.value=input.value;
text.setAttribute("readonly","readonly");
del.innerHTML='<i class="fa fa-solid fa-trash"></i>';
edit.innerHTML='<i class="fa fa-solid fa-pen"></i>';
content.appendChild(text);
actions.appendChild(del);
actions.appendChild(edit);
content.appendChild(actions);
abox.appendChild(content);
par.appendChild(abox);
text.classList.add("content");
del.classList.add("del");
edit.classList.add("edit");
content.classList.add("box");
actions.classList.add("actions");
del.addEventListener("click",()=>{
abox.removeChild(content);
});
edit.addEventListener("click",()=>{
if (edit.innerHTML == '<i class="fa fa-solid fa-pen"></i>') {
edit.innerHTML = '<i class="fa fa-solid fa-download"></i>';
text.removeAttribute("readonly");
text.focus();
text.style.color="rgb(80, 95, 85)";
text.style.fontWeight="bold";
text.style.cursor="text";
} else {
edit.innerHTML='<i class="fa fa-solid fa-pen"></i>';
text.setAttribute("readonly", "readonly");
text.style.color="black";
text.style.cursor="default";
text.style.fontWeight="normal";
}
});
clear.addEventListener("click",()=>{
abox.removeChild(content);
});
input.value="";
}