Skip to content

Instantly share code, notes, and snippets.

@jakebresnehan
Created March 6, 2012 06:02
Show Gist options
  • Save jakebresnehan/1983968 to your computer and use it in GitHub Desktop.
Save jakebresnehan/1983968 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