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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:02:38+00:00 2026-05-23T07:02:38+00:00

The easiest way for me to explain the question is by you looking at

  • 0

The easiest way for me to explain the question is by you looking at my code at jsfiddle

each Div has only one link which once clicked sets the Div to active + shows a hidden Div within it. So when you click the link again it toggles the active style and hides the hidden Div. this is how I want it, but i am also wanting it so that if I click on another link and the previous Div is still set to active it will only set that Div(just clicked) as active and toggle the previous div.

I hope this makes sense if you need any more info let me know.

Also If you see a better way of coding this little piece of code, I would love suggestions.

Thanks.

  • 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-23T07:02:38+00:00Added an answer on May 23, 2026 at 7:02 am

    If your markup guarantees that all of the related divs are siblings, this works (and without using any IDs or attributes):

    $('.href').click(function (ev){
        ev.preventDefault();
    
        // find enclosing div
        var p = $(this).closest('div');
    
        // make this one active, and make others inactive
        $(p).addClass('active')
            .siblings('.active').removeClass('active').find('.hidden').hide();
    
       // and change the hidden div
        $(p).find('.hidden').toggle();
    })
    

    http://jsfiddle.net/alnitak/y8kys/

    The middle line does the hard work – it ensures the outer div has the right class, that none of its siblings does, and that the hidden elements in every sibling are also hidden.

    I put another version at http://jsfiddle.net/alnitak/ZfhbU/ which works when the enclosing divs aren’t siblings.

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

Sidebar

Related Questions

The easiest way to explain my question may be with an example, so let
The easiest way to explain this problem is to show you some code: Public
Easiest way to explain what I mean is with a code sample. This doesn't
I think the easiest way to explain is simply linking to an example of
this is prob pretty easy but if someone could explain the easiest way to
What's the easiest way to search a div for a text string using jquery?
Which is the easiest way to validate a file and to prevend changing it's
I think the easiest way to explain this is by example. I have a
The easiest way I see to explain what I need is via example. Suppose
The easiest way to ask this question would be to show you all through

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.