I tried saving the notes to local storage in different ways, but nothing worked. I also asked AI tools for help, but the solutions didn’t fix the problem or were too hard to follow. I’m still stuck and need clear, simple guidance to solve this.
let note_list=document.getElementById("note_list_container")
function addNote(){
let input_note=document.getElementById("note").value
if(input_note){
let copyButton=document.createElement("button")
copyButton.className="copy_button"
copyButton.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="white"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"/></svg>`
copyButton.onclick=function copyContent(){
navigator.clipboard.writeText(input_note) //creating copy paste button !
}
let deleteButton=document.createElement("button")
deleteButton.className="delete_button"
deleteButton.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="white"><path d="m791-55-91-91q-49 32-104.5 49T480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-60 17-115.5T146-700l-91-91 57-57 736 736-57 57ZM480-160q43 0 83.5-11t78.5-33L204-642q-22 38-33 78.5T160-480q0 133 93.5 226.5T480-160Zm334-100-58-58q22-38 33-78.5t11-83.5q0-133-93.5-226.5T480-800q-43 0-83.5 11T318-756l-58-58q49-32 104.5-49T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 60-17 115.5T814-260ZM537-537ZM423-423Z"/></svg>`
deleteButton.onclick=function deleteNote(){
display_note.style.display="none" //creating delete note button, the delete button is created further down the page but its still working !
}
let editButton=document.createElement("button")
editButton.innerHTML="edit"
let display_note=document.createElement("p")
display_note.className="note_info" //appeding each button to our note
display_note.textContent=input_note
note_list.appendChild(display_note)
display_note.appendChild(deleteButton)
display_note.appendChild(copyButton)
document.getElementById("note").value=""
display_note.appendChild(editButton);
//creating a variable that will hold the localstorage
//checks if there are any notes saved, if not it generates the localstorage
editButton.onclick=function(){ //logic for editing the note and than saving the change
let edit_form=document.createElement("input")
edit_form.value=display_note.textContent
edit_form.type="text"
let save=document.createElement("button")
save.textContent="save"
save.onclick=function(){
display_note.textContent=edit_form.value
display_note.appendChild(deleteButton)
display_note.appendChild(copyButton)
display_note.appendChild(editButton)
}
display_note.innerHTML="" //emptying the html of the form so only the edit form and the save button appears
display_note.appendChild(edit_form)
display_note.appendChild(save)
}
}
}