-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (42 loc) · 1.26 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
let notesContainer = document.querySelector(".notes-container");
let createNotes = document.querySelectorAll(".input-box");
let btn = document.querySelector(".button");
const showNotes = () => {
notesContainer.innerHTML = localStorage.getItem("notes");
};
showNotes();
const updateStorage = () => {
localStorage.setItem("notes", notesContainer.innerHTML);
};
btn.addEventListener("click", () => {
let para = document.createElement("p");
let icon = document.createElement("i");
para.setAttribute("contenteditable", "true");
para.className = "input-box";
para.innerText = "enter here.....";
icon.classList.add("fa-solid", "fa-trash");
notesContainer.appendChild(para).appendChild(icon);
attachKeyupListener(para);
});
function attachKeyupListener(element) {
element.onkeyup = () => {
updateStorage();
};
}
createNotes.forEach((notes) => {
attachKeyupListener(notes);
});
notesContainer.addEventListener("click", (e) => {
if (e.target.tagName === "I") {
e.target.parentElement.remove();
updateStorage();
}
// else if (e.target.tagName === "P") {
// createNotes = document.querySelectorAll(".input-box");
// createNotes.forEach((notes) => {
// notes.onkeyup = () => {
// updateStorage();
// };
// });
// }
});