Forked from jakebresnehan/Simple-HTML5-Local-Storage.js
Created
April 2, 2020 13:12
-
-
Save 404ryannotfound/7cd77ccae0904f2d363bb2d887bf5e47 to your computer and use it in GitHub Desktop.
Simple HTML5 Local Storage example to hide a element
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
<button id="hide-button">Hide</button> | |
<button id="show-button">Show</button> | |
<div id="sign-up-form"> | |
<p>Sign up form</p> | |
</div> |
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
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