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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:40:43+00:00 2026-05-31T00:40:43+00:00

Im trying to make my jquery expand when clicked anywhere ( except the top

  • 0

Im trying to make my jquery expand when clicked anywhere ( except the top left box ) and try to collapse when clicking only in the ( top left box )

http://jsfiddle.net/wzbAh/1/

HTML:

<div id="box">
    <div class="collapsed container" >
        <div class="nav" class="closed">0</div>
        box 1 - click me    
        <div class="expanded_content">
            extra content only for expanded state
        </div>
        <div class="collapsed_content">
            collapsed only content #1
        </div>
    </div>

    <div class="collapsed container">

        <div class="nav" class="closed">0</div>
        box 2 - click me    
        <div class="expanded_content">
            extra content only for expanded state
        </div>
    </div>
    <div class="collapsed container">

        <div class="nav" class="closed">0</div>
        box 3 - click me    
        <div class="expanded_content">
            extra content only for expanded state
        </div>
    </div>
</div>

JavaScript:

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

$("#box").delegate(".container.expanded .nav ", "click", function(e) {

    $(this).addClass("collapsed");
});

Seems to be almost there but not quite, what would be the right way to do it? Since toggle seems not the option here.

  • 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-31T00:40:44+00:00Added an answer on May 31, 2026 at 12:40 am

    Here you go mate…

    $("#box").delegate(".container", "click", function(e) {
        if ($(e.target).hasClass("container")) {
            $(this).addClass("expanded");
        }
    });
    
    $("#box").delegate(".container.expanded .nav", "click", function(e) {
        $(this).parent().removeClass("expanded");
        e.stopPropagation();
    });
    

    ​

    The class “collapsed” is never removed so to remove the expanded state you need to use removeClass("expanded"), so it goes back to its initial state. Also, when the .nav element is clicked, the div you want to affect is the parent.

    Finally, e.stopPropagation() stops the click firing both event handlers and removing the class and then adding it again.

    Here’s a working jsfiddle…

    http://jsfiddle.net/wzbAh/11/

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

Sidebar

Related Questions

I'm trying to make this jquery plugin => http://leandrovieira.com/projects/jquery/lightbox/ work with multiple galleries on
im trying to make jquery box drag, but the problem is that when i
I am trying to make a jquery menu that when I click on one
I'm trying to figure out how to make jQuery slide #content2 down and replace
I'm trying to find/make a good jquery drop-down menu with animation (fadein/fadeout or slidedown)
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I'm trying to make a modal dialog in the least amount of jQuery code
I am trying to make a livesearch with Django and jQuery. What I've done
I'm trying to make a drop down menu using javascript/jquery but can't get my
I am trying to make two ajax requests in parallel using jQuery like this:

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.