Skip to content

Instantly share code, notes, and snippets.

@avand
Created July 29, 2016 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avand/c2ea0242f358c59f0a15bdf75df14131 to your computer and use it in GitHub Desktop.
Save avand/c2ea0242f358c59f0a15bdf75df14131 to your computer and use it in GitHub Desktop.
var form = document.querySelector("#new-item-form");
var list = document.querySelector("#todo-list");
form.addEventListener("submit", formSubmitted);
loadList();
function formSubmitted(event) {
event.preventDefault();
// Assume that elsewhere we've defined the createItem function...
input.value.split(",").forEach(createItem);
form.reset();
saveList();
}
function saveList() {
// Get the HTML contents of the list...
var html = list.innerHTML;
// Write the HTML to local storage...
localStorage.setItem("listHTML", html);
}
function loadList() {
// Read the saved HTML from local storage...
var html = localStorage.getItem("listHTML");
// Set it to the list HTML...
list.innerHTML = html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment