1

I i have a button which show/hide a div on onClick event. I want to remeber the state, on click keep div hidden for one day (set cookie which expires) and on another click keep div showed (delete cookie).

I need remember this state on whole domain.

What is the easiest way? I´am the beginner, I prefer jquery-cookie - it is possible to use? I can´t find any example where is this explained on onClick event.

Thanks alot!

RASAE
  • 35
  • 5

2 Answers2

0

Have a look at the jquery-cookie plugin.

The documentation is just here.

Here's an example in jsfiddle on how to use it (set cookie / unset cookie / display cookie) : http://jsfiddle.net/rdtome/73vzD/239/

(See the lines) :

$.cookie('test_cookie', 'hello cookie !'); // SET cookie
$.removeCookie('test_cookie'); // DELETE cookie
$.cookie('test_cookie'); // GET cookie
rtome
  • 1,894
  • 2
  • 20
  • 25
  • I have seen this link - but I donť know how to use it on onClick event with button. I need I simple example with functional solution. – RASAE Jul 27 '15 at 16:25
  • 1
    Have a look at the jsfiddle in the answer. Also here : http://jsfiddle.net/rdtome/73vzD/239/ – rtome Jul 27 '15 at 16:58
0

Please find the URL for Better way cookie management. Create, read, and erase cookies with jQuery

OR

for set cookie:
    $.cookie('cookieName', 'value', { expires: 7 });
for read cookie:
    $.cookie('the_cookie');

for Delete cookie:// set nulll for delete
    $.cookie('the_cookie', null);

for more information. http://www.jquerybyexample.net/2012/06/jquery-cookies-get-set-and-delete.html

Community
  • 1
  • 1
Neo Vijay
  • 743
  • 7
  • 13