-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
104 lines (76 loc) · 3.23 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const addNotesBtn = document.querySelector('#add');
const storeUpdateLocalStorageData=()=>{
const textAreaData=document.querySelectorAll('textarea');
const notesData=[];
textAreaData.forEach((note)=>{
return notesData.push(note.value);
})
// console.log(notesData);
localStorage.setItem('notesData',JSON.stringify(notesData));
};
const addNewNotes = (text=' ') => {
const note = document.createElement('div');
note.classList.add('note');
// <label for="note" class="lab_Not">Leave a Note </label>
const htmlData = `
<div class="operation">
<button title="edit" class="edit"><i class="fa-solid fa-user-pen"></i></button>
<button title="delet" class="delete"><i class="fa-solid fa-trash"></i></button>
</div>
<div class="main ${text ? " ": "hidden"}" >${text}</div>
<textarea class="${text ? "hidden": " "}">${text}</textarea>
</div> `;
note.insertAdjacentHTML('afterbegin', htmlData);
// console.log(note);
document.body.appendChild(note);
// console.log(document.body.appendChild(note));
// getting reference
const btnEdit = note.querySelector('.edit');
const btnDelete = note.querySelector('.delete');
const tagMainDiv = note.querySelector('.main');
const textArea = note.querySelector('textarea');
// console.log(btnDelete, btnEdit,tagMainDiv.textArea);
btnEdit.addEventListener('click',()=>{
tagMainDiv.classList.toggle('hidden');
textArea.classList.toggle('hidden');
})
// Static put text value
// textArea.value=text;
// tagMainDiv.innerHTML=`Arka`;
// textArea.addEventListener('input',(event)=>{
// const userValue=event.target.value;
// console.log(userValue);
// })
textArea.addEventListener('change',(event)=>{
const userValue=event.target.value;
// console.log(userValue);
tagMainDiv.innerHTML=userValue;
//Save data in local storage(session )
storeUpdateLocalStorageData();
})
// element.addEventListener('click', function(event) {
// // The 'event' argument contains information about the click event.
// // You can access event properties like event. target, event.type, etc.
// // Perform actions based on the event.
// });
btnDelete.addEventListener('click', () => {
note.remove();
storeUpdateLocalStorageData();
})
}
// getting localStorage data return
// Retrieve data from localStorage
const returnNotesData = JSON.parse(localStorage.getItem('notesData'));
console.log(returnNotesData);
// Check if there's data in localStorage
if (returnNotesData) {
// Iterate through each item in the data and call addNewNotes
returnNotesData.forEach((noteData) => {
// Call addNewNotes function with the noteData as an argument
addNewNotes(noteData);
});
}
// const returnNotesData=JSON.parse(localStorage.getItem('notesData'));
// console.log(returnNotesData);
// if(returnNotesData){returnNotesData.forEach((note)=>addNewNotes(note))};
addNotesBtn.addEventListener('click', () => addNewNotes());