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

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -

SQL Server - MyCTE query based on 24 hour period (next day) -