-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (55 loc) · 1.77 KB
/
Copy pathscript.js
File metadata and controls
78 lines (55 loc) · 1.77 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
74
75
76
77
78
let frm = document.querySelector("#note");
let inp = document.querySelector("#inp");
let txt = document.querySelector("#txt");
let arr = JSON.parse(localStorage.getItem("notes")) || [];
function createCard(obj) {
let forCard = document.querySelector(".forCard");
let card = document.createElement("div");
card.className =
"card h-65 w-90 lg:w-45 lg:h-55 bg-blue-600 p-3 shadow-xl/30 flex flex-col justify-between rounded-lg";
let textdiv = document.createElement("div");
let h3 = document.createElement("h3");
h3.className = "text-xl font-bold text-white";
h3.textContent = obj.title;
let hr = document.createElement("hr");
hr.className = "text-white border";
let p = document.createElement("p");
p.className = "py-3 text-white";
p.textContent = obj.note;
let btnDiv = document.createElement("div");
btnDiv.className = "flex flex-col items-center";
let delbtn = document.createElement("button");
delbtn.className =
"delbtn pl-1 pr-1 bg-red-600 shadow-xl/20 text-white hover:bg-red-700";
delbtn.textContent = "Delete";
btnDiv.appendChild(delbtn);
textdiv.appendChild(h3);
textdiv.appendChild(hr);
textdiv.appendChild(p);
card.appendChild(textdiv);
card.appendChild(btnDiv);
forCard.appendChild(card);
delbtn.addEventListener("click", function () {
let index = arr.indexOf(obj);
if (index !== -1) {
arr.splice(index, 1);
localStorage.setItem("notes", JSON.stringify(arr));
}
card.remove();
});
}
arr.forEach(function (obj) {
createCard(obj);
});
frm.addEventListener("submit", function (e) {
e.preventDefault();
let obj = {
title: inp.value,
note: txt.value
};
arr.push(obj);
localStorage.setItem("notes", JSON.stringify(arr));
createCard(obj);
inp.value = "";
txt.value = "";
});