-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (38 loc) · 1.23 KB
/
script.js
File metadata and controls
43 lines (38 loc) · 1.23 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
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', () => {
let inputBox = document.createElement('p');
let img = document.createElement('img');
inputBox.classList.add('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(note => {
note.onkeyup = function() {
updateStorage();
}
})
}
})
document.addEventListener("keydown", event=>{
if(event.key==="enter"){
document.execCommand('insertLineBreak');
event.preventDefault();
}
})