-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 1.31 KB
/
index.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
const notesContainer = document.querySelector(".notes-container");
const createBtn = document.querySelector(".btn");
let notes = document.querySelectorAll(".input-box");
createBtn.addEventListener("click", function() {
let inputBox = document.createElement("p");
let img = document.createElement("img");
inputBox.className = "input-box";
inputBox.setAttribute("contenteditable", "true");
img.src = "./images/delete.png"
notesContainer.appendChild(inputBox).appendChild(img);
saveData();
});
notesContainer.addEventListener("click", function (e) {
if (e.target.tagName === "IMG") {
e.target.parentElement.remove();
saveData();
} else if (e.target.tagName === "P") {
notes = document.querySelectorAll(".input-box");
notes.forEach(nt => {
nt.onkeyup = function () {
saveData();
}
});
}
});
function saveData() {
localStorage.setItem("notes", notesContainer.innerHTML);
}
function showData() {
notesContainer.innerHTML = localStorage.getItem("notes");
}
showData();
document.addEventListener("keydown",event=>{ /* to get into different line */
if(event.key==="Enter"){
document.execCommand("insertLineBreak");
event.preventDefault();
}
})