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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:33:11+00:00 2026-06-06T16:33:11+00:00

I try to use the toggle function of the Bootstrap collapse plugin programmatically. I

  • 0

I try to use the toggle function of the Bootstrap collapse plugin programmatically.
I manage to toggle a div when I click on the link in accordion-heading but it works only once, that is to say I cannot click again to hide the div.

Here is my code :

<div id="accordion" class="accordion">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a id="program${bean.id}" data-parent="#accordion" 
                   class="accordion-toggle">
            ...
            </a>
        </div>
        <div id="collapse${bean.id}" class="accordion-body collapse">
            <div class="accordion-inner">
            ...
        </div>
    </div>
</div>

And later in the JSP :

$.each($('#accordion a.accordion-toggle'), function(i, link){
    $(link).on('click', 
        function(){
            // ...
            $('#collapse' + id_of_a_bean).collapse({
                toggle : true,
                parent : '#accordion'
            });
            // ...
        }
    )
});

Did I miss something?

  • 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-06T16:33:13+00:00Added an answer on June 6, 2026 at 4:33 pm

    I would guess this happened to a lot of people.

    When you call the collapse function (FYI or any bootstrap function), if you pass an object it means that you initiate the collapse. The toggle option only toggles once on invocation (doc).

    You have to call once with the parameters, and then call only with the action, as a string.

    $.each($('#accordion a.accordion-toggle'), function(i, link){
        var $collapsible = $('#collapse' + id_of_a_bean); // Let's be thorough
    
        $collapsible.collapse({
            toggle : true, // May not be necessary anymore
            parent : '#accordion'
        });
    
        $(link).on('click', 
            function(){
                // ...
                $collapsible.collapse('toggle'); // Here is the magic trick
                // ...
            }
        );
    });
    

    Live demo : http://jsfiddle.net/Sherbrow/uycBa/

    Just to be precise, you can only call once the init process, since it aborts if you have already done it on the same element. That’s why it worked only one time.

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

Sidebar

Related Questions

I try use string as a regular expression pattern but I've following errors PHP
I try to use a variable in my kshell script but can't get a
i try to use jquery .text() but not really work : Before <a id=group_name
I try to use the columnFilter add-on of jquery datatable but I couldn't make
I use this script : <script language=javascript> function toggle() { var ele = document.getElementById(mydiv);
i try to implement the accordion jquery for toggle slide down and slide up
CODE: $(document).ready(function() { $('.toggle').hide(); $('.show').click(function(){ $('.toggle').toggle('slow'); $(this).attr('src','images/checkmark2.jpg'); },function(){ $('.toggle').toggle('slow'); $(this).attr('src', 'images/checkmark1.jpg'); return false; });
how to generate random number in this code? I try use $RANDOM, but the
I try to use this code for toggling text on the link: var showText=<span>Open</span>
I try use gssapi32.dll in my application but I receive exception when app start

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.