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

  • Home
  • SEARCH
  • 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 8808721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:41:33+00:00 2026-06-14T02:41:33+00:00

I’m using jQuery to add a Class to a few elements. I’m not new

  • 0

I’m using jQuery to add a Class to a few elements.

I’m not new to adding classes, nor removing them. But I’m still somewhat intermediate with styles and any flexibility styles can perform to single elements.

Here’s what’s going on:

I have 2 Divs that I’m affecting with jQuery:

<div id="columnleft">stuff in here</div>
<div id="columncenter">bigger stuff in here</div>

In a nutshell, column left is about 155px wide, while columncenter is positioned relative to columnleft, with a margin-left of 162px

Here’s my styles:

<style>
#columnleft {
  float:left; 
  position:relative;
  text-align:left;
  width:155px; 
}

#columncenter {  
  position:relative; 
  padding-bottom:50px
  margin:0; 
  margin-left:162px; 
}
</style>

I’m basically toggling these 2 divs with the jQuery examples below:

So far I’ve gotten these 2 separate instances to work:

$("#columnleft").hide();
$("#columncenter").css("margin","0px");

then……..

$("#columnleft").show();
$("#columncenter").css("margin-left","162px");

Though this works, I’m not quite satisfied.
I’d prefer to create a class or two that I can use to toggle the hiding of columnleft, while also changing the margin-left at the same time.

It’s all fine with the example above, when I’m only using jQuery. But there are times when a page loads, and the columnleft is meant to be hidden, and columncenter is meant to be expanded, from the beginning. Would be nice to not need jQuery to enter the scene at those moments.

All I could come up with is:

<style>
.disappear { display:none; }
.maximize { margin:0px;  margin-left:0px; }
</style>

When the page loads:

<div id="columnleft" class="disappear">stuff in here</div>
<div id="columncenter" class="maximize">bigger stuff in here</div>

it seems that columncenter is ignored. (columnleft indeed does disappear)
Also, toggling with jquery, the same result occurs.

Column Center hates me!
Does anyone see where I’m missing the mark?

  • 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-06-14T02:41:35+00:00Added an answer on June 14, 2026 at 2:41 am

    View JSFiddle: http://jsfiddle.net/tuanderful/bTZq8/

    What if you had another div that contains both #columnleft and #columncenter, and has a class of .hide-left or .show-left:

    <div class="hide-left">
        <div id="columnleft">stuff in here</div>
        <div id="columncenter">bigger stuff in here</div>
    </div>
    

    ​
    Then add the following CSS:

    .show-left #columnleft {
        display: block;
    }
    .show-left #columncenter {
        margin-left: 162px; 
    }
    
    .hide-left #columnleft {
        display: none;
    }
    .hide-left #columncenter {
        margin-left: 0; 
    }
    

    You can update your jQuery to simply toggle the .hide-left or .show-left classes on the parent container.

    What I did here is similar to adding .disappear and .maximize styling, but I added a bit of context around the two columns. The neat thing is that all of the styling is handled purely by CSS – when you want to show or hide your sidebar, you only need JavaScript to update the state of the container; that is, change the class in the container from hide to show or vice versa.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.