JasonMHirst
JasonMHirst

Reputation: 576

jQuery Accordion - Setting "Active Panel" during load

Having a strange issue that I 'think' I know what the problem is but don't know how to resolve it.

I have a page that contains a jQueryUI Accordion, I'm trying to set the "Activate" during runtime, but I can only get this to work if I put an "Alert();" before!

I do have a number of getJSON calls that populates the contents of the Accordion (determines how many panels it has to have) and once this is complete then needs to jump to the appropriate panel.

The actual call is here:

function jumpToAccordionDate(d,m,y){
var el3=$('#h'+d +  m +  y);
$('#accordion').accordion('activate',el3);}

Previously, during the creation of the accordion, I've already set the id of the H3 element by the following:

$('#accordion').append('<h3 id="h' + dd + '"><a href="#">' + cDate + '</a></h3><div id="div' + dd + '"></div>').accordion('destroy').accordion();

Is there someway of, maybe waiting for the Accordion to totally finish rendering on the DOM before I call the jumpToAccordionDate, or is there a better alternate?

Upvotes: 0

Views: 764

Answers (1)

Andrew Whitaker
Andrew Whitaker

Reputation: 126042

I think the create event might solve your timing issue. The documentation is a little vague, but you could tap into it like this:

$("#accordion").accordion({
    create: function() {
        jumpToAccordionDate(...);
    }
});

Upvotes: 1

Related Questions