Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created February 24, 2014 23:57
Show Gist options
  • Save slopeofhope81/9199861 to your computer and use it in GitHub Desktop.
Save slopeofhope81/9199861 to your computer and use it in GitHub Desktop.
todo app using local storage
$(function(){
$("#add").click(function(){
var description=$("#description").val();
if(description === ""){
$("#alert").html("<strong>Warning</strong> You left the todo app!");
$("#alert").fadeIn().delay(1000).fadeOut();
return false;
}
$("#todos").prepend("<li><input type='checkbox' name='checkbox'>"+ description+ "</li>");
$("#form")[0].reset();
var todos = $("#todos").html();
localStorage.setItem("todos", todos);
return false;
})
if (window.localStorage.getItem("todos")){
$("#todos").html(localStorage.getItem("todos"));
return false;
}
$("#clear").click(function(){
window.localStorage.clear();
location.reload();
return false;
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment