Forked from jakebresnehan/Simple-HTML5-Local-Storage.js
Created
April 12, 2020 12:35
-
-
Save Nemra1/83e705d7879f9c7607ac17bf63d5687e 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