Reputation: 9
I'm currently trying to figure out how to make a jQuery toggle button which hides a banner on my website remember if it has been hidden with a simple cookie. Perhaps jQuery cookie?
The code is incredibly simple however I have never coded any cookies in my life and javascript isn't my expertise.
Javascript:
<script>
$(document).ready(function(){
$("button").click(function(){
$(".adultbanner").hide(1000);
});
});
</script>
HTML:
<div class="adultbanner">
<div class="adultwrap">
<h1><i class="fa fa-ban"></i></h1>
<h2>You must be at least 18 years of age to use this website. To find out more information click <a href="#">here...</a></h2>
<button>Hide</button>
</div>
</div>
Any help would be appreciated.
Upvotes: 0
Views: 145
Reputation: 2085
I think the simplest and best supported solution would be to use http://plugins.jquery.com/cookie/
$.cookie('bannerHidden', true, { expires: 7 });
The last parameter makes the cookie expire in a week, or you can simply omit that to have the cookie kept indefinitely.
Upvotes: 1
Reputation: 122
Well you can use localstorage if you are using html5 to store information.
Upvotes: 0