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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:25:35+00:00 2026-06-14T17:25:35+00:00

I wrote an alternative to the jQuery Accordion, as that didn’t offer multiple open

  • 0

I wrote an alternative to the jQuery Accordion, as that didn’t offer multiple open section support (any idea why they opted to not include support for that? What’s the history there?). I did some research on StackOverflow, as well on Google to see what other options others came up. I needed something that could be used on the fly on multiple elements.

After seeing several solutions and experimenting with them, in the end, I wrote my own version (based on Kevin’s solution from http://forum.jquery.com/topic/accordion-multiple-sections-open-at-once , but heavily modified).

jsFiddle can be found here: http://jsfiddle.net/3jacu/1/

Inline Code:

$(document).ready(function(){

$.fn.togglepanels = function(){
    return this.each(function(){
        h4handler = $(this).find("h4");
        $(h4handler).prepend('<div class="accordionarrow">&#9660;</div>');
        $(h4handler).click(function() {
            $(h4handler).toggle(
                function() {
                    barclicked = $(this);
                    $(barclicked).find(".accordionarrow").html('&#9658;');
                    $(barclicked).next().slideUp('slow');
                    window.console && console.log('Closed.');
                    return false;
                }, 
                function() {
                    barclicked = $(this);
                    $(barclicked).find(".accordionarrow").html('&#9660;');
                    $(barclicked).next().slideDown('slow');
                    window.console && console.log('Open.');
                    return false;
                }
            );
        });
    });
};

$("#grouplist").togglepanels(); }

Oddly, the accordion arrow at the right side stopped working once I pasted it in jsFiddle, while it works in my local copy.

In any case, the issue is that toggling isn’t working as expected, and when it does, it fires duplicate toggle events which result in it closing, opening, then ultimately closing the section and it won’t open from that point on (it toggles open then closes back). That’s assuming it works! At first, it won’t work as it doesn’t respond. I think there’s a logic error somewhere I’m missing.

From what I wrote/see in the code, it searches the given handle for the corresponding tag (in this case, h4), pops the handle into a variable. It then adds the arrow to the h4 tag while applying the accordionarrow class (which floats it to the right). It then adds a click event to it, which will toggle (using jQuery’s toggle function) between two functions when h4 is clicked.

I suspect the problem here is that I may be mistakenly assuming jQuery’s toggle function will work fine for toggling between two functions, that I’ll have to implement my own toggle code. Correct me if I’m wrong though!

I’m trying to write the code so it’ll be as efficient as possible, so feedback on that also would be appreciated.

Thanks in advance for your time, assistance, and consideration!

  • 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-14T17:25:36+00:00Added an answer on June 14, 2026 at 5:25 pm

    You have the toggle binding (which is deprecated by the way) inside of the click binding, so a new event handler is getting attached every time you click the header.

    As a random aside you should also fire events within the plugin (where you have the console lines would make sense) so that external code can react to state changes.

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

Sidebar

Related Questions

I wrote an alternative fonction to open AutoCAD drawings. However, AutoCAD made it really
Is there any alternative to cross domain xml loading than with XML()? I wrote
I wrote a PHP script that retrieves values from a MySQL Query. I used
I wrote a Flickr search engine that makes a call to either a public
Is there any buildin function or a alternative simple and fast way of escape
I wrote a regular expression in hope that I will be able to replace
I'm looking for a JQuery-style javascript/CSS control that will allow the user to drill
I wrote a simple jquery validation plugin for learning puposes, and it works fine.
I wrote code for one application.In that I wrote IME_ACTION_DONE for edit text.All other
I have a simple 2d strategy combat game that I wrote in javascript and

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.