Search code examples
javascriptcookiesjquery-cookie

Use cookie for Javascript function


I have a Javascript function :

$('.myclass').click(function() {
  $('.myclass2').each(function(e) {
    $(this).removeClass('myclass3').addClass('myclass4');
  });
});

I would wish that the changes remain all the time for the user with jquery cookie.

Do you know how can it be done?


Solution

  • Use jQuery Cookie plugin:

    Set a cookie

    $.cookie("example", "foo");
    

    Get a cookie

    alert($.cookie("example"));