A Pen by Richard Craig on CodePen.
Created
September 3, 2015 08:35
-
-
Save riccraig/620a75da02f6790c4ae0 to your computer and use it in GitHub Desktop.
OyJzNo
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
<div> | |
<button id="add">Add</button> | |
<button id="clear">Clear</button> | |
</div> | |
<ul id="list"> | |
<script> | |
document.write(localStorage.getItem("dd-cache")); | |
</script> | |
</ul> | |
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
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", ''); | |
}); |
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
<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