Set cookie on cookie message to show or hide a div

I have a cookie message inside a div, and a button to close it down.

If they simply click the close button I would like to set a cookie to expire after say a week, and then when the cookie expires the div appears again, until it expires the div stays hidden.

This is the div I want to show if no cookie set and hide until the cookie expires, and the close button is inside it.

I found some code to use as it seems about as close as I can get it, but I need some help to get it working the way I need it too.

Basically it shows on initial display, inside they have an option to set the cookie, but if they dont and just click close I want to set a cookie so that this div doesn’t then appear for another week.

<div id="cookieControlOnLoad">
<div class="container">
    ....
    <span class="close" id="cookieClose" onclick="CheckCookieAndHideDiv();">&#215;</span>    
</div>
</div>

if (getCookie("HideDiv") != "true") {
                $(".cookieControlOnLoad").css('display', 'none');
            }
function CheckCookieAndHideDiv() {
           setCookie('HideDiv', 'true', 1);
           $(".cookieControlOnLoad").css('display', 'none');
 }

When I try and set the cookie above, its not working as a simple start. Was trying to set it and then see about adding the expire after a week.

Shouldn’t that be

if (getCookie('HideDiv') === 'true') {
  $('.cookieControlOnLoad').css('display', 'none')
}

then?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.