Stefan D.
Stefan D.

Reputation: 13

How to set cookie for close button

I want to set cookie when the button close is pressed to prevent the dialog box to open again.

This is my code:

<div class="card">
  <span class="clickable" data-effect="fadeOut"><i class="fa fa-times"></i></span>
    <div class="card-blockquote">Free shipping </div>
</div>

<script>
jQuery('.close-icon').on('click',function() {
  jQuery(this).closest('.card').fadeOut();
})
</script>

UPDATE:

I add this library:

<action method="addLinkRel"><rel>text/javascript</rel><href>https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.2/js.cookie.js</href></action>

and I use the following code:

 $.cookie('card', 'card', { expires: 7 });

and I have in console:

TypeError: $.cookie is not a function

Upvotes: 0

Views: 1837

Answers (1)

Chathura Edirisinghe
Chathura Edirisinghe

Reputation: 367

You can use cookie generators. here

<script>
jQuery('.close-icon').on('click',function() {
  jQuery(this).closest('.card').fadeOut();
$.jCookies({
    name : 'Your_cookie_Namee',
    value : {cookie values}
});

})
</script>

So if you want to use localstorage, you can use this

Upvotes: 1

Related Questions