-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (45 loc) · 1.71 KB
/
script.js
File metadata and controls
58 lines (45 loc) · 1.71 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
const notesContainer = document.querySelector(".notes-container");
const createBtn = document.querySelector(".btn");
let notes = document.querySelectorAll(".input-box");
//when we close and open browser....it should check the local storage
//if there is any data...it should display data...as a note
function showNotes(){
notesContainer.innerHTML = localStorage.getItem("notes");
}
showNotes();
// store note on local storage..so that when we refresh...old notes should not disappear
function updateStorage(){
localStorage.setItem("notes", notesContainer.innerHTML);
}
//a new note will appear when we click on Create Notes
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);
})
//to delete the note when we click on remove icon
notesContainer.addEventListener("click", function(e){
//when click on image...note deleted
if(e.target.tagName == "IMG"){
e.target.parentElement.remove();
updateStorage();
}
//when write anything in p-tag...storage updated
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.preventDefault();
// }
// })