Created
July 29, 2016 00:34
-
-
Save avand/c2ea0242f358c59f0a15bdf75df14131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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