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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:55:03+00:00 2026-06-13T23:55:03+00:00

When I place them inside of multiple divs, it does not seem to work

  • 0

When I place them inside of multiple divs, it does not seem to work any longer. What am I missing? Thanks

Demo: http://jsfiddle.net/HVfaA/206/

<div id="content">
<div id="first">
<div id="first-1">
<div id="first-2">
<div id="first-3">
<li><a href="#" class="one">One</a></li>
<li><a href="#" class="two">Two</a></li>
<li><a href="#" class="three">Three</a></li>
<li><a href="#" class="four">Four</a></li>
</div>
</div>
</div>
</div>
<div id="second">
<div id="second-1">
<div id="second-2">
<div id="second-3">
<div id="one">One</div>
<div id="two">Two</div>
<div id="three">Three</div>
<div id="four">Four</div>
</div>
</div>
</div>
</div>
</div>

$("div#second > div").hide();
var divs = $("#one, #two, #three, #four");
$('li a').on('click', function () {
$(divs).hide();
$("#" + $(this).attr("class")).show();
});​

This function is a modified version of the one offered by Peter Ajtai jQuery show div on click, hide the others

Original question below:
I was trying use a separate divs containing the links and to show the divs.
Currently When the links are clicked, the hidden divs do not show. Thanks for your help.
Here’s the demo on the jsfiddle – http://jsfiddle.net/HVfaA/184/

<div id="first">
<li><a href="#" class="one">One</a></li>
<li><a href="#" class="two">Two</a></li>
<li><a href="#" class="three">Three</a></li>
<li><a href="#" class="four">Four</a></li>
</div>
<br /><br />
<div id="second">
<div id="one">One</div>
<div id="two">Two</div>
<div id="three">Three</div>
<div id="four">Four</div><br/><br/>
</div>

// Optional code to hide all divs
$("div#second").hide();

// Selector
var divs = $("#one, #two, #three, #four");

// Show chosen div, and hide all others
$("li a").click(function () 
{
$("#" + $(this).attr("class")).show();
divs.not(("#" + $(this).attr("class"))).hide();
});
  • 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-13T23:55:04+00:00Added an answer on June 13, 2026 at 11:55 pm

    The issue is that you’ve wrapped all your divs in div#second and then hidden that element. Because their parent is hidden, none of the child divs (#one, #two, #three, #four) will show up.

    If you’d like to hide all divs to begin with try

    // Optional code to hide all divs
    $("div#second > div").hide();
    

    This isn’t directly related, but as an aside you can leave off your divs.not(("#" + $(this).attr("class"))).hide(); by just shifting the order of when you hide your divs (hide them all, then show the one). Also, since you already stored them as divs you can also just reference them directly.

    // Show chosen div, and hide all others
    $("li a").click(function () {
        $(divs).hide();
        $("#" + $(this).attr("class")).show();
    });​
    

    See updated Fiddle http://jsfiddle.net/HVfaA/190/

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

Sidebar

Related Questions

how can you find all links (no anchors) and place them inside a list,
I've created some custom menus and I'd like to place them somewhere fixed inside
I have three view on the same place. I need to show them like
I have multiple Node applications (build on Express framework). Now I have placed them
My place of work currently uses CVS. A git migration is planned but it
My controls receives some params from the user, I would like to place them
I want to place a number of images inside a form and be able
Possible Duplicate: How do I match any character across multiple lines in a regular
This should be fairly simple, but I seem to be missing something. I'm working
I want to place many divs in a form of a circle. I will

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.