NGriffin
NGriffin

Reputation: 81

Setting a cookie to close div

Recently we added a bar to warn users our site users cookies, with an accept button that is meant to close and set a cookie so it would not show for some time, however in practice this doesn't actually work.

I was wondering if someone could let me know what I might have got wrong with this following code (The Accept button is the action button for the cookie.):

<div class="pea_cook_wrapper pea_cook_bottomright">
        <p>TEXT <a href="#" id="fom">more information</a> <button id="pea_cook_btn" class="pea_cook_btn" href="#">Accept</button></p>
    </div><div class="pea_cook_more_info_popover">
        <div class="pea_cook_more_info_popover_inner">
         <p>TEXT</a>
            <p><a href="#" id="pea_close">Close</a></p>
        </div>
    </div><script type="text/javascript">
        jQuery(document).ready(function($){
            $("#fom").click(function() {
              $(".pea_cook_more_info_popover").fadeIn("slow");
              $(".pea_cook_wrapper").fadeOut("fast");
            });
            $("#pea_close").click(function() {
              $(".pea_cook_wrapper").fadeIn("fast");
              $(".pea_cook_more_info_popover").fadeOut("slow");
            });
            $('#pea_cook_btn').click(function() {
                var today = new Date();
                var expire = new Date();
                var expireTimer = 7776000;
                document.cookie = "peadigCookie=set;";
            $(".pea_cook_wrapper").fadeOut("fast");
            });
        }); </script>

Thanks,

NG

Upvotes: 1

Views: 658

Answers (1)

isJustMe
isJustMe

Reputation: 5470

You can download the jquery cookie plugin , it will help you to simplify the usage, and you can read the values on your code and change the layouts with your logic.

$.cookie("example", "foo");//sets cookie
$.cookie("example", "foo", { expires: 7 }); //sets cookiewith expiry time
$.cookie("example") //gets cookie
$.cookie("example", null); //deletesthe cookie

Upvotes: 3

Related Questions