Skip to content

Instantly share code, notes, and snippets.

@chriscoyier
Created April 13, 2011 17:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chriscoyier/917936 to your computer and use it in GitHub Desktop.
Save chriscoyier/917936 to your computer and use it in GitHub Desktop.
// Save all data, on some kind of event
localStorage.setItem("doesHaveData", "yeahBaby");
var data = $("#contest-vote").serializeArray();
jQuery.each(data, function(i, obj) {
localStorage.setItem(obj.name, obj.value);
});
// Get all data back, test on page load
if (localStorage.getItem("doesHaveData")) {
var data = $("#contest-vote").serializeArray();
jQuery.each(data, function(i, obj) {
$("[name='"+ obj.name +"']").val(localStorage.getItem(obj.name));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment