- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
December 1, 2015 at 10:27 am #9620vemundParticipant
Trying to make a jQuery cookie hide/show box using JS Cookie, but I somehow can’t make it work. The box won’t display at all. I’m using Shopify.
#pop-up { display: none; }
Jquery:
<script type='text/javascript'>//<![CDATA[ $(window).load(function(){ // if no cookie if (!$.cookie('alert')) { $( "#pop-up" ).show(); $("#hide").click(function() { $( "#pop-up" ).slideUp( "slow" ); // set the cookie for 24 hours var date = new Date(); date.setTime(date.getTime() + 24 * 60 * 60 * 1000); $.cookie('alert', true, { expires: date }); }); } });//]]> </script>
The rest:
<div id="pop-up"> <div id="center" class="box"> 40% off today only<br> <a id="hide" href="#">OK, thanks!</a> </div> </div>
December 1, 2015 at 10:41 am #9621niki-van-steinParticipantIt does not work because you can only store strings in cookies. You store the string
"true"
instead of the boolean valuetrue
.Try the following code where I replaced the check with
!= "true"
.<script type='text/javascript'>//<![CDATA[ $(window).load(function(){ // if no cookie if ($.cookie('alert')!="true") { $( "#pop-up" ).show(); $("#hide").click(function() { $( "#pop-up" ).slideUp( "slow" ); // set the cookie for 24 hours var date = new Date(); date.setTime(date.getTime() + 24 * 60 * 60 * 1000); $.cookie('alert', "true", { expires: date }); }); } });//]]> </script>
A working jsfiddle: http://jsfiddle.net/bqam0qb4/1/
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.