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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:27:43+00:00 2026-05-15T21:27:43+00:00

First question ever asked at stackoverflow. So, problem is: Two accordion declarations on document.ready

  • 0

First question ever asked at stackoverflow.
So, problem is:
Two accordion declarations on document.ready (jquery 1.4.2 and jquery ui 1.8.2):

       $(document).ready(function () {
        $("#accordion").accordion({
            header: 'h3'
        });

        $("#accordion2").accordion({ 
            header: 'h4' 
        });

        $(function () {
            $(".get-index").click(function () {
                var activecontent = $("#accordion").accordion("option", "active");
                alert(activecontent);                   
            });
        });
    });

HTML:

<div id="accordion">
    <h3><a href="#">Section 1</a></h3>
    <div>
        Content Section 1: Parent
        <div id="accordion2">
            <h4><a href="#">SubSection 1</a></h4>
            <div>content section 1: child</div>
            <h4><a href="#">SubSection 2</a></h4>
            <div>content section 2: child</div>
            <h4><a href="#">SubSection 3</a></h4>
            <div>content section 3: child</div>
            <h4><a href="#">SubSection 4</a></h4>
            <div>content section 4: child</div>
        </div>
    </div>
    <h3><a href="#">Section 2</a></h3>
    <div>
        Content Section 2: Parent
    </div>
    <h3><a href="#">Section 3</a></h3>
    <div>
        Content Section 3: Parent
    </div>
    <h3><a href="#">Section 4</a></h3>
    <div>
        Content Section 4: Parent

        <button type="button" class="get-index ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all">
            <span class="ui-button-text">index</span>
        </button>

    </div>
</div> 

And finally: what’s wrong and why “activecontent” is 7? I know, that there are 4 parent panels + 4 child panels and starting from 0, it is 7. But I’m trying to get index of last parent panel and it should be 3.

Any help much appreciated.

Code posted: http://jsbin.com/eqewe

  • 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-15T21:27:44+00:00Added an answer on May 15, 2026 at 9:27 pm

    Unfortunately this is a bug in jQuery UI, in the accordion code:

    o.active = o.collapsible && clickedIsActive ? false 
      : $('.ui-accordion-header', this.element).index(clicked);
    

    It’s finding any $('.ui-accordion-header'), not just the header selector you specified and not only immediate children. I’ll put this in as a bug with the jQuery UI guys, the .active property really should be set differently. I’ve entered a bug with the jQuery UI team for this here: http://dev.jqueryui.com/ticket/5841


    You can work-around it for now by finding the element yourself with .index(), like this:

    $(function () {
      $(".get-index").click(function () {
        var a= $("#accordion").children('.ui-state-active').index('#accordion > h3');
        alert(a);                   
      });
    });​
    

    You can try it out here

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

Sidebar

Related Questions

This is my first question ever here on stackoverflow! I've been searching for a
This is my first question ever on StackOverflow, hurray! I can honestly say I
First question ever on stackoverflow. Been reading for some time now, while trying to
My first question ever, so I'll try to be as descriptive as possible. I
Here's my HTML. Apologies for formatting - this is my first-ever question! <div id=Template>
First question on Stackoverflow (.Net 2.0): So I am trying to return an XML
I asked a similar question like this yesterday but after waiting for ever I
this is my first ever question. I am developing a iPad app that allows
this is my first time ever posting a question and I am kind of
First, iReport is the worst reporting tool I've ever used. Now to my question.....

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.