Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Nemra1/83e705d7879f9c7607ac17bf63d5687e to your computer and use it in GitHub Desktop.
Save Nemra1/83e705d7879f9c7607ac17bf63d5687e to your computer and use it in GitHub Desktop.
Simple HTML5 Local Storage example to hide a element
<button id="hide-button">Hide</button>
<button id="show-button">Show</button>
<div id="sign-up-form">
<p>Sign up form</p>
</div>
Need to include Modernizer (http://www.modernizr.com/) and jQuery (http://jquery.com/)
$(document).ready(function($){
if (Modernizr.localstorage) {
$('#hide-button').click(function(e){
localStorage.setItem('subscribed',true);
$('#sign-up-form,#hide-button').hide();
$('#hide-button').hide();
$('#show-button').show();
});
$('#show-button').click(function(e){
localStorage.setItem('subscribed',true);
localStorage.clear();
$('#sign-up-form,#hide-button').show();
$('#show-button').hide();
});
var is_subscribed = localStorage.getItem('subscribed');
if(is_subscribed){
console.log('localStorage')
$('#sign-up-form,#hide-button').hide();
}
if(!is_subscribed){
console.log('no localStorage');
$('#sign-up-form').show();
$('#show-button').hide();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment