-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notes.js
39 lines (37 loc) · 1.23 KB
/
Notes.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
const NotesContainer = document.querySelector(".Notes-container");
const createBtn = document.querySelector(".btn");
const Notes = document.querySelectorAll(".input-box");
function UpdateStorage() {
localStorage.setItem("Notes",NotesContainer.innerHTML);
}
function ShowNotes() {
NotesContainer.innerHTML = localStorage.getItem("Notes");
}
ShowNotes();
createBtn.addEventListener("click", ()=>{
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);
})
NotesContainer.addEventListener("click", function(e){
if(e.target.tagName === "IMG"){
e.target.parentElement.remove();
UpdateStorage()
}else if(e.target.tagName === "p"){
Notes = document.querySelectorAll("input-box");
Notes.forEach(nt => {
nt.onkeyup =function(){
UpdateStorage();
}
})
}
document.addEventListener("keydown",Event =>{
if(Event.key ==="enter"){
document.execCommand("insertLineBreak");
Event.parentDefault();
}
})
})