Reputation: 55
I have simple code:
<html>
<head>
<script src="lib/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function () {
$('.close_i').click(function(){
$('.adsbox').hide();
$('.open_i').show();
});
$('.open_i').click(function(){
$('.adsbox').show();
$('.open_i').hide();
});
});
</script>
</head>
<body>
<div class="adsbox">
<img src="as1.jpg">
<img src="as2.jpg">
<img src="as3.jpg">
<img src="as4.jpg">
<img src="as5.jpg">
<img src="as6.jpg">
<a class="close_i">Close ADS</a>
</div>
<a class="open_i" style="display:none;">Open ADS</a>
</body>
</html>
I want this: when a user clicks on the "Close ADS", there are the following jQuery instructions:
$(document).ready(function () {
$('.close_i').click(function(){
$('.adsbox').hide();
$('.open_i').show();
});
$('.open_i').click(function(){
$('.adsbox').show();
$('.open_i').hide();
});
});
and cookie plugin, save the adsbox status in the user's browser for 3 days.
My question is: How can I use jQuery Cookie ?! i dont know this explanation : jquery Cookie plugin.
Can you give me some working code?
Thanks.
Upvotes: 0
Views: 882
Reputation: 9530
First you have to do this:
$(document).ready(function () {
$('.close_i').click(function(){
$('.adsbox').hide();
$('.open_i').show();
$.cookie("Disclaimer", 1, { expires : 3 });
});
$('.open_i').click(function(){
$('.adsbox').show();
$('.open_i').hide();
$.removeCookie("Disclaimer");
});
});
If he closed the adds, whenever he enter the page again the adds must be closed (3 days from now on), so you have to add this also:
$(document).ready(function () {
if ($.cookie("Disclaimer")){
$('.adsbox').hide();
$('.open_i').show();
});
});
Upvotes: 2