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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:13:27+00:00 2026-05-23T08:13:27+00:00

I recently found some very easy to use Jquery code, which basically toggles and

  • 0

I recently found some very easy to use Jquery code, which basically toggles and div visible and not visible.

The code is working on the first div – but lets say I have multiple with the same structure listing down, and I want the toggle to work on the specific second or third div im clicking.

Im wondering if it’s possible to expand the following code to be dynamic for that.

Example with two divs (only first one will work):

<a id="toggle" href="javascript:void(0);">Expand box 1</a> 
<div id="content">Content 1</div> 
<div id="contentHidden" style="display:none;">Hidden 1</div>

<br><br>

<a id="toggle" href="javascript:void(0);">Expand box 2</a> 
<div id="content">Content 2</div> 
<div id="contentHidden" style="display:none;">Hidden 2</div>

Jquery:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript">

$(function() // run after page loads 
{ 
  $("#toggle").click(function() 
  {  
    // hides matched elements if shown, shows if hidden 
    $("#content, #contentHidden").toggle(); 
  }); 
});
  • 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-23T08:13:27+00:00Added an answer on May 23, 2026 at 8:13 am

    First, an Id should be unique on each DOM tree object.
    (multiple div with id=”toggle” would eventually work but is not recommanded. Prefer the class attribute in this case.)

    for your problem I suggest :

    <a class="toggle" href="javascript:void(0);">Expand box 1</a> 
    <div class="content">Content 1</div> 
    <div class="contentHidden" style="display:none;">Hidden 1</div>
    
    <br><br>
    
    <a class="toggle" href="javascript:void(0);">Expand box 2</a> 
    <div class="content">Content 2</div> 
    <div class="contentHidden" style="display:none;">Hidden 2</div>
    

    and the jQuery code :

    $(function()
    {
        $(".toggle").click(function() 
        {  
            // hides children divs if shown, shows if hidden 
            $(this).children("div").toggle(); 
        }); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I recently found some source code which used a particular technique(idiom?) I hadn't
Recently I have found some classes in our system which are not covered by
A coworker recently showed me some code that he found online. It appears to
I've found it very weird that simple code like this is not valid: select
I've found myself having to write some VBA code recently and just wondered if
Recently scalaz caught my eye. It looks very interesting, but I have not found
Recently I reviewed some C code and found something equivalent to the following: struct
I found this in some production login code I was looking at recently... HttpContext.Current.Trace.Write(query
I began studying Java Regular Expression recently and I found some really intersting task.For
I've found recently that for some types of financial calculations that the following pattern

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.