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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:42:24+00:00 2026-05-17T22:42:24+00:00

I admit to being somewhat of a copy and paste JavaScript developer (with a

  • 0

I admit to being somewhat of a copy and paste JavaScript developer (with a strong background in other languages). I’m using the jQuery accordion, and using cookies to save the selected accordion section. I found some code which I integrated into my code. The key section is as follows.

change: function (event, ui) {
     var index = $(this).find("h3").index(ui.newHeader[0]);
     $.cookie(accordion, index);
}

This works, but I hate using code I don’t understand. I understand that the index is discovered by using the find method (which makes the assumption that I don’t have any h3s within the content), but what I don’t understand is what the ui.newHeader[0] is doing. What is the newHeader array, and what is its purpose here?

Thanks,
Erick

  • 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-17T22:42:25+00:00Added an answer on May 17, 2026 at 10:42 pm

    Looking at the source for jquery.ui.accordion.js, it’s just an object that contains the newly selected element.

    You can see for yourself if you just check out the source:

    // find elements to show and hide
    var toShow = clicked.next(),
        toHide = this.active.next(),
        data = {
            options: options,
            newHeader: clickedIsActive && options.collapsible ? $([]) : clicked,
            oldHeader: this.active,
            newContent: clickedIsActive && options.collapsible ? $([]) : toShow,
            oldContent: toHide
        },
            down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] );
    
        this.active = clickedIsActive ? $([]) : clicked;
        this._toggle( toShow, toHide, data, clickedIsActive, down );
    
        return;
    },
    

    newHeader is not an array, it’s an object that represents the newly selected element. The code you posted finds all h3 elements in the accordion element, and then it takes the index of the newHeader. The element that newHeader represents changes each time the accordion changes.

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

Sidebar

Related Questions

I admit, I don't know too much about javascript, mostly I just steal and
In the admin interface and newforms there is the brilliant helper of being able
I admit it: I don't bother with too much exception handling. I know I
I admit - I'm a complete novice when it comes to unit testing. I
I admit this is not strictly a programming question, although I do use my
I'll be the first to admit that this is cut and past programming. I've
More times than I'd like to admit I've had people new to a project
First of all I have to admit that my programming skills are pretty limited
This might seem like a stupid question I admit. But I'm in a small
As far as I know (not much I'll admit), the currently popular programming paradigms

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.