Skip to content

Instantly share code, notes, and snippets.

@riccraig
Created September 3, 2015 08:35
Show Gist options
  • Save riccraig/620a75da02f6790c4ae0 to your computer and use it in GitHub Desktop.
Save riccraig/620a75da02f6790c4ae0 to your computer and use it in GitHub Desktop.
OyJzNo
<div>
<button id="add">Add</button>
<button id="clear">Clear</button>
</div>
<ul id="list">
<script>
document.write(localStorage.getItem("dd-cache"));
</script>
</ul>
function save(){
$('#list').find('script').remove();
var h = $('#list').html();
localStorage.setItem("dd-cache", h);
}
var cnt = 0;
$('#add').click(function(){
$('<li>Hello ' + cnt + ': ' + new Date() + '</li>').appendTo('#list');
cnt++;
save();
});
$('#clear').click(function(){
localStorage.setItem("dd-cache", '');
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment