I am creating todo list to display sample static data. If I click button sample data append to the list one by one. When I click Delete Button deleted correctly. If i want to refresh the page given displayed data shows in the page and also I click the content to edit the content in the page after refresh the page the edited content displayed in the page. These values are displayed from the localstorage. My question is how to store the same inserted and edit values are stored in the local storage using javascript.. My sample code is Given
this my script to add and edit content. I want to create Local storage and and store the add and edit values store in the local storage.. After refresh the page Last created/edited values show in the List..
<button class="addbtn icon-plus" id="addnew" onclick="addSticky()">Add</button>
<ul id="mynotes"></ul>
var ul = document.getElementById("mynotes");
var index=0;
function addSticky()
{
var el=document.createElement("li");
el.setAttribute("class","mylist");
var cbtn=document.createElement("button");
cbtn.setAttribute("class","close");
cbtn.innerHTML="X";
cbtn.setAttribute("onclick", "removeSticky()");
var text=document.createElement("div");
text.setAttribute("class","content");
text.setAttribute("id","contentid_"+index);
text.innerHTML="Sample content";
el.appendChild(pin);
el.appendChild(cbtn);
el.appendChild(text);
ul.appendChild(el);
index++;
var edit_data = document.getElementsByClassName('content');
for (var i=0; i < edit_data.length; i++) {
edit_data[i].addEventListener('click', edit);
};
}
function removeSticky() {
var clear = this.event.currentTarget.parentNode;
ul.removeChild(clear);
}
function edit(){
var id = this.getAttribute('id');
//alert(id);
document.getElementById(id).contentEditable="true";
//localStorage.clear();
}