-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.js
More file actions
52 lines (41 loc) · 1.51 KB
/
note.js
File metadata and controls
52 lines (41 loc) · 1.51 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
const addBtn = document.getElementById('addBtn');
const notes = JSON.parse(localStorage.getItem('notes'));
const note = document.querySelector('.note');
const deleteAll = document.querySelector('.clearAll');
const nav= document.querySelector('nav'),
changingbtn = nav.querySelector('.changingbtn');
changingbtn.addEventListener('click', ()=> {
nav.classList.toggle('open');
});
addBtn.addEventListener('click', () => {
const container = document.createElement('div');
container.classList.add('container');
// const note = document.createElement('div');
// note.classList.add('note');
container.innerHTML = `
<div class="note">
<input type="text">
<textarea ></textarea>
<button class="delete"> <i class="fas fa-trash-alt"></i></button>
</div>
`
const deleteBtn = container.querySelector('.delete');
deleteBtn.addEventListener('click', () => {
container.remove();
updatelocalstorage();
});
updatelocalstorage();
document.body.appendChild(container);
});
function updatelocalstorage() {
const notesTxt = document.querySelectorAll('textarea');
const notes = [];
notesTxt.forEach((note) => {
notes.push(note.value);
});
localStorage.setItem('notes', JSON.stringify(notes));
}
deleteAll.addEventListener('click', ()=> {
// notes= [];
document.querySelector('.note').innerHTML = '';
});