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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:07:22+00:00 2026-05-28T05:07:22+00:00

css: #container_im.collapsed{ background-color:red; height: 48px; margin-bottom: 10px; margin-right: 10px; width: 227px; } #container_im.expanded{ background-color:green;

  • 0

css:

#container_im.collapsed{
    background-color:red;
    height: 48px;
    margin-bottom: 10px;
    margin-right: 10px;
    width: 227px;
}

#container_im.expanded{
    background-color:green;
    height: 348px;
    margin-bottom: 10px;
    margin-right: 10px;
    width: 227px;
}

#expanded_content{
    height:100px;
    color: yellow;
    display: none;
}

//default state
//expand box
#nav.closed {
    height:20px;
    width:20px;
    background-color: black;
    color:white;
}

#nav.opened {
    height:20px;
    width:20px;
    background-color: white;
    color:black;   
}

html:

<div id="container_im" class="collapsed" >


    <div id="nav" class="closed">0</div>
    box 1 - click me    

    <div id="expanded_content">
        extra content only for collapsed state
    </div>

</div>

js:

    <div id="nav" class="closed">0</div>
    box 2 - click me    

    <div id="expanded_content">
        extra content only for collapsed state
    </div>

</div>




***//
$(document).bind("click", function(e) {
    $(e.target).closest("#container_im").toggleClass("expanded");
    $(e.target).closest("#expanded_content").show();
     $(e.target).closest("#nav").toggleClass("closed");
});***

http://jsfiddle.net/NsBWy/14/

Any JS guru that could help me fix this jquery code?

  • Trying to display the text #expanded_content to display only when the selected box is clicked. And hide the complete #expanded_content div and all of its children upon another click ( toggle )
  • Trying to restyle the #nav div and only the one currently clicked

Any good ideas on how to make it better are welcome also,
a bit stuck on how to implement above features after trying some things from the manual its the combination of functions I don’t see at this point.

  • 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-28T05:07:23+00:00Added an answer on May 28, 2026 at 5:07 am

    You have lots of things wrong in your approach. Take a look at this working jsFiddle and then I’ll writeup some of the things you had wrong:

    http://jsfiddle.net/jfriend00/A9rKm/

    $("#box").delegate(".container", "click", function(e) {
        $(this).toggleClass("expanded collapsed");
    });
    

    Things you had wrong:

    1. You can only have one object with a given id so you should be using class names, not ids for common elements.
    2. You can use this to access the clicked on item.
    3. You don’t want to be putting event handlers on the document if you can avoid it. I created a common parent that you can put the event handler on and then used .delegate() from the version of jQuery you chose (1.5) to automatically filter them for me. With jQuery 1.7+, you would use .on() instead of .delegate().
    4. You can use more than one class with .toggleClass() to toggle multiple classes at once.
    5. .closest() looks up the parent chain, not anywhere else. You use .find() if you’re looking for children of a particular type.
    6. You don’t need to use so many separate classes that indicate the open/close state. One class on a common parent can be used by CSS for all children. Thus, I was able to eliminate all of the other class changes.
    7. CSS comments must be of the form /* comment here */. You can’t use // for CSS comments.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CSS: .jC2_Container{ } .jC2_EventWrapper { border-right:1px solid #CDC3FF; height:20px; width:250px; } .jC2_EventNum { float:left;
My Css #container{ display:block; } #container ul{ list-style:none; position:relative; margin:0px; padding:0px; display:block; } #container
I have a container div with the following CSS: #container { position:relative; overflow:hidden; width:200px;
I have a container: <div id=container><h1>LONG TITLE LINE</h1></div> and css: #container { width: 50%;
I have the following CSS, What im trying to do is have the background
i'm trying to insert an image in a div container using css and html,
If you use the container class for a layout with blueprint-css, you end up
What are the best practices when naming CSS selectors? SomeContainerContent some_container_content some-container-content I read
I want: all links which not contained filename (not .html, .jpg, .png, .css) redirect
I am looking at the jquery site at the contains selector. $(div:contains('John')).css(text-decoration, underline); How

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.