Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6038365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:12:32+00:00 2026-05-23T06:12:32+00:00

I am using JQuery as a layout switch which works fine, but when the

  • 0

I am using JQuery as a layout switch which works fine, but when the user refreshes the page none of the layout options are ‘saved’ if you know what I mean. Is there a way to remember which switch option is selected even if user refreshes/changes page?

For example, if the post-area bg is black and text white, the switch will invert those colours, and will stay unless the user switches back.

I used to do this with php, but I want to do this without php, just jq if somehow possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:12:33+00:00Added an answer on May 23, 2026 at 6:12 am

    You will definitely need to set a cookie for this if you want to do it with jQuery (or store local data using HTML5 but that is not as universally used or browser accepted, nor needed).

    This is a pretty basic function to set a cookie, from here:

    function set_cookie(c_name, value, exdays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value;
    }
    

    and this is a pretty basic one to get a cookie, also from here:

    function get_cookie(c_name){
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++)
        {
          x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
          y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
          x=x.replace(/^\s+|\s+$/g,"");
          if (x==c_name)
            {
            return unescape(y);
            }
          }
    }
    

    So something like this should work:

    var bg_color = get_cookie('bg_color');
    if (bg_color != null) { // may want to do more verification here, as well
        $('body').css('backgroundColor', '#' + bg_color);
    }
    else {
        $('body').css('backgroundColor', '#FFF');
    }
    

    and then whenever you want to save the color, just set it like:

    set_cookie('bg_color', color, 10); // will save `color` in the cookie for 10 days
    

    EDIT After posting this it occurred to me there is probably a built in function with jQuery to set/get cookies or at least a very good plugin. This page has some good references.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am using jquery layout plugin from http://layout.jquery-dev.net/ . my options are following:
I want to know that can we build a data object using jquery/json, which
Using jQuery, how would you find elements which have a particular style (eg: float:
Using jQuery's dialog I came across the following quirk (tested in FF3): User selects
I am using jquery layout and I have a very hard time getting rid
I am using the jQuery layout plugin and the jqGrid plugin in one of
I am using jquery layout for the first time. I have it working using
I am going to using jQuery UI.Layout Plug-in with JQuery UI resizable plugin. the
I am using jQuery UI to get a nice 3 tab layout using their
I'm using jQuery Masonry (google it, it's super awesome) for my site's dynamic layout.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.