-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.js
More file actions
42 lines (37 loc) · 1.27 KB
/
note.js
File metadata and controls
42 lines (37 loc) · 1.27 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
const notescontainer = document.querySelector(".notes-container");
const createbtn = document.querySelector(".btn");
let notes = document.querySelectorAll(".input-box");
function shownotes(){
notescontainer.innerHTML=localStorage.getItem("notes")
}
shownotes();
function updatestorage(){
localStorage.setItem("notes",notescontainer.innerHTML);
}
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);
})
notescontainer.addEventListener("click", function(e) {
if (e.target.tagName === "IMG") {
e.target.parentElement.remove();
updatestorage(); // Assuming updateStorage is defined elsewhere
} else if (e.target.tagName === "P") {
const notes = document.querySelectorAll(".input-box");
notes.forEach(nt => {
nt.onkeyup = function() {
updatestorage(); // Assuming updateStorage is defined elsewhere
}
});
}
});
document.addEventListener("keydown",event =>{
if(event.key === "Enter"){
document.execCommand("insertLinebreak")
event.preventDefault();
}
})