javascript - How can I save my custom width to a cookie? -


i'm working on width changer. use jquery this, i've problem. idea when user clicks button, width changes instantly. i'd save user's selection in cookie, don't know how can do.

current jquery code:

$(function() {   $(".width-changer").on("click", function(e)   {     $(".wrapper").toggleclass("custom-width");   }); }); 

i use plugin cookie:

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.js"></script> 

it in index.html.

the wrapper class global width.

this solution worked me in i.explorer & firefox, chrome think should enable cookies :

$(function() {     if ($.cookie('custom_width')=='true') { //add true condition         $(".wrapper").addclass("custom-width");     };    $(".width-changer").on("click", function(e)   {     $(".wrapper").toggleclass("custom-width");      if($(".wrapper").hasclass("custom-width"))         $.cookie('custom_width', 'true');     else         $.cookie('custom_width', 'false');    }); }); 

hope solution you.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -