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 6967553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:20:12+00:00 2026-05-27T16:20:12+00:00

I am trying to make a layout switcher. A user clicks a certain div

  • 0

I am trying to make a layout switcher. A user clicks a certain div called display, it then toggles a class called display-grid to that class strictly for visual.

At the same time it toggles some classes on and off for my layout.

I have a left column and a right column, the object is to let a user choose which column is on which side of the page. Like a sidebar can be on the left or right side of the page.

Every time they toggle this change it either adds or removes the classes from my 2 other divs (the class are just adding a float: left; and float:right; and swaps them out on each toggle click.

Now on each toggle it also saves the state to a user cookie, so if they change the sidebar location, it will persist across the site for them.

My code is sloppy I do not know 100$ how to do this, but I did ,manage to get it working and then it stopped. Well EVERYTHING described above works except the cookie’s are giving me an issue now, they are not setting a cookie each time a change is made. This is weird because about 10 hours ago I had it working so I cannot figure out what happend.

I am hoping someone with more knowledge of Javascript can help me get this working or possibly even improve it but getting it working for now would make my day.

Below is the code I have this far.

Not included is the jQuery library but I have included the cookie plugin.

 $(window).load(function(){
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

My code

jQuery.noConflict();
jQuery(document).ready(function ($) {
  // Layout Switcher for post list

  // Load existing setting from Cookie
  if ($.cookie('MODE_SWITCHER') == 'null') {
    $('#content-left').attr('class', 'right-sidebar')
    $('#content-right').attr('class', 'left-sidebar')
  } else{
     $('#content-right').attr('class', 'right-sidebar')
     $('#content-left').attr('class', 'left-sidebar')
  }
  // Change LIVE by clicking the Toggle button on the site, save new value to Cookie
  $('.display').click(function () {
        $(this).toggleClass('display-grid');
        $('#content-left').toggleClass('left-sidebar').toggleClass('right-sidebar');
        $('#content-right').toggleClass('right-sidebar').toggleClass('left-sidebar');

        if ($('#content-left').hasClass('left-sidebar')) {
           var postmode = 'leftbody';
        } else {      //var postmode = 'right-sidebar';
          var postmode = '';
        }
        // save preference to Cookie
        $.cookie('MODE_SWITCHER', postmode, {
          path: '/',
          expires: 10000
        });
        return false;
  });
});

HTML

<span class="display" title="Change Layout">List/Grid</span>

<div id="content-left"> Left column content </div>

<div id="content-right"> Right column content </div>

CSS

.display {
    float:left;
    width: 49px;
    height: 20px;
    margin-top: -2px;
    background: url(http://codedevelopr.com/uploads/grid-switcher.gif) no-repeat 0 0;
    text-indent: -5555em;
    overflow: hidden;
    cursor: pointer;
     -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -o-user-select: none;
    user-select: none;
}
.display-grid {
    background: url(http://codedevelopr.com/uploads/grid-switcher.gif) no-repeat 0 -20px;
}

.grid-content .gridrow {

border-bottom: 1px solid #ECEDE8;

margin: 0 15px;

}

.left-sidebar{
    float:left !important;
    margin-right:15px;
}
.right-sidebar{
    float:right !important;
    margin-right:15px;
}
  • 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-27T16:20:13+00:00Added an answer on May 27, 2026 at 4:20 pm

    You have a return statement right before your cookie code so the cookie code will never be reached:

        // save preference to Cookie
        return false;
        $.cookie('MODE_SWITCHER', postmode, {
          path: '/',
          expires: 10000
        });
        return false;
    

    Remove that first return statement and let your cookie code get executed.

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

Sidebar

Related Questions

I am trying to make Layout that contains 2 layout, vertical and horizontal scrolls.
I'm trying to make a layout that is something similar to how the android
I'm trying to make a 2 column layout using class=left and class=right, at the
I'm trying to make a two-column page using a div-based layout (no tables please!).
I'm trying to make a CSS table that (for layout purposes) has a caption
I'm trying to make a centered, 100% high layout that has NO FIXED width
I'm trying to make a layout first two textviews in a vertical arrangement, then
I have been trying to make a layout for an Android app that functions
I am trying to make it such that the layout looks like the following
I am trying to make a chatroom layout like the following: Now my problem

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.