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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:34:49+00:00 2026-06-02T01:34:49+00:00

I want to add three toggle functions on one page (all with the same

  • 0

I want to add three toggle functions on one page (all with the same classes).

My JavaScript code:

<script type="text/javascript">
    $(document).ready( function() {
        $('.toggle_container').hide();
        $('.trigger').click( function() {
            var trig = $(this);
            if ( trig.hasClass('trigger_active') ) {
                trig.next('.toggle_container').slideToggle('slow');
                trig.removeClass('trigger_active');
            } 
            else {
                $('.trigger_active').next('.toggle_container').slideToggle('slow');
                $('.trigger_active').removeClass('trigger_active');
                trig.next('.toggle_container').slideToggle('slow');
                trig.addClass('trigger_active');
            };
            return false;
        });
    });
</script>

This is my HTML code:

<div id="tourteaser">
<div id="tourteaser_teaser" class="erster">
    <span class="zahlen">1</span>
    <h3>headline</h3>
    <p>Erstelle deine persönliche Visitenkarte und zeige deine Kunst!</p>
    <a class="trigger" href="" onfocus="this.blur();"></a>
    <div class="toggle_container">
        <div class="trenner"></div>
        <div class="tourinfos"></div>
    </div>
</div>

<div id="tourteaser_teaser" class="mitte">
    <span class="zahlen">2</span>
    <h3>headline</h3>
    <p>Erstelle deine persönliche Visitenkarte und zeige deine Kunst!</p>
    <a class="trigger" href="" onfocus="this.blur();"></a>
    <div class="toggle_container">
        <div class="trenner"></div>
        <div class="tourinfos"></div>
    </div>
</div>

<div id="tourteaser_teaser" class="letzter">    
    <span class="zahlen">3</span>
    <h3>headline</h3>
    <p>Erstelle deine persönliche Visitenkarte und zeige deine Kunst!</p>
    <a class="trigger" href="" onfocus="this.blur();"></a>
    <div class="toggle_container">
        <div class="trenner"></div>
        <div class="tourinfos"></div>
    </div>
</div>

</div>

By now: only one (the first) toggle reacts to this function. How do I make all three work on its own? It would be also fine if one toggle closes when another one is clicked. Is that easy possible?

EDIT: I uploaded an example of my site because I can’t get SpYk3HH’s example to work with mine. See: http://www.brayaz.de/example/example.html

  • 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-02T01:34:51+00:00Added an answer on June 2, 2026 at 1:34 am

    You had a flaw by design, but I got it working with the following;

    JS

    $(function(){
        $('.toggle_container').hide();
        $('.trigger').on("click", function(e) {
            $(this).toggleClass("trigger_active").next('.toggle_container').slideToggle('slow');
        });
    });​
    

    Change in HTML

     <a class="trigger" href="" onfocus="this.blur();"></a>
    

    to

    <a class="trigger" href="javascript:void(0);" onfocus="this.blur();"></a>
    

    See

    WORKING JSFIDDLE HERE!

    UPDATE

    Found one major issue, first of all, it’s NEVER a good idea to give multiple elements the same ID, consider changing <div id="tourteaser_teaser" to something like <div id="tourteaser_teaser-x" where x is the index number of that element. Second, I see you did it for the purpose of CSS, in this case you want to give them all the same CLASS name, not the same ID. You can have many class names as you like but only one ID.

    I think I fixed all of your problems, here’s what I did:

    • As mentioned before I changed your HTML on <a href="" to <a href="javascript:void(0);".
      • This removes the need to return false on click command
    • Changed the ID’s tourteaser_teaser to tourteaser_teaser-1, tourteaser_teaser-2, & tourteaser_teaser
    • Added the class tourteaser_teaser to each div that had that ID previously
    • Adjusted CSS to fit new changes
    • also noticed .trigger was set to position: absolute; and because the parent was static, all of your links were overlapping
      • to solve this i simple set the parent to position: relative;
    • Simplified your JS to what you see in my previous example

    Please see the NEW UPDATE JSFIDDLE and tell me if that’s what you’re looking for?

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

Sidebar

Related Questions

I want add my custom sidebar next right column all page. Please check this
I want to add three variables into the same table cell and separate them
I want to add three labels into a cell dynamically, cell is created dynamically
All I want to know is if there's an easy way to add lines
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)
I want to add Toggle show-rows like Google analytics top content. At the bottom
I want to add a handler that keeps on executing while a gwt toggle
I want to add three buttons on a web form. Each button has its
i have add three series in a stacked graph. i want to add value
I have a dictionary with three objects, and I want to add this dictionary

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.