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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:11:36+00:00 2026-05-28T15:11:36+00:00

Ok well I need some help because I am plain stuck. I am trying

  • 0

Ok well I need some help because I am plain stuck. I am trying to make a simple drop down type menu which will be used for a different purpose then a navigation menu. But anyway I can get it to work perfectly, I just need some help simplyfing the code. Here is the html:

<div class="big">
    <a href="#" id="atog1">Hello</a>
    <a href="#" id="atog2">Hello</a>
    <a href="#" >Hello</a>
    <a href="#">Hello</a>
<br clear="all">
    <div id="drop" class="atog1">This is a toggled div1!</div>
    <div id="drop" class="atog2">This is a toggled div2!</div>
</div>

Here is the Jquery initial code that works beautifully but I am going to need to have up to 20 different a and divs to show and I do not want all that code. So I am trying to put it in a clean simple short snippet of code:

//Make the toggled div
$('#atog1').show();
$('div.atog1').hide();
$('#atog1').click(function(){
    $('div.atog2').hide();
    $('div.atog1').slideToggle();
});
//Make the toggled div2
$('div.atog2').hide();
$('#atog2').click(function(){
    $('div.atog1').hide();
    $('div.atog2').slideToggle();   
});

And here is where I got stuck, This is what is supposed to be a shorter version of the above, but when I click on the first a it opens div and when I click on the second a it hides first div but then if I click on the first a again it does not hide div:

$('div[class^=atog]').hide();

$('a').click(function(){
    var tid = $(this).attr('id');
    $('div#drop[class!='+tid+']').hide();
    $('div#drop[class='+tid+']').slideToggle();
});

I know there should be a really simple solution, but I can just not see it. Thanks to anyone in advance and here is my jsfiddle if that is more helpful!
http://jsfiddle.net/liveandream/stGF9/

  • 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-28T15:11:37+00:00Added an answer on May 28, 2026 at 3:11 pm

    You can’t have multiple elements with the same id.

    You should use classes when they need to be shared. Here is one example of how you could change it.

    http://jsfiddle.net/stGF9/54/

    $('div.drop').hide();
    
    $('a').click(function(){
        var tid = $(this).attr('id');
        var el = $('div.drop.'+tid);
    
        $('div.drop').not(el).hide();
        el.slideToggle();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well i need some help here i don't know how to solve this problem.
Well, I need to make simulator for non-deterministic Push-Down Automaton. Everything is okey, I
Well i need to make it so any user can have a foo.com/username in
I'm a beginner in ruby and in programming as well and need help with
I need a JavaScript library that supports Ajax as well as help me in
after trying to solve the problem without and with help I'm still stuck. My
I'm writing an application and need some help with consistently storing and loading preferences
I'm just starting out with the whole ajax thing and I need some help.
i just started dabbling in php and i'm afraid i need some help to
I need to involve some markup and javascript people to help development team on

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.