views:

414

answers:

5

I'm not getting how to do this, or if I can do this. I have an accordion, multiple sections with each section containing multiple anchor tags each with a unique string id. I'd like to be able to have the accordion open to where a particular element with a given id is. Like say id "item117". Can I use something like

$('#accordion').activate('activate','#item117');

or even

$('#accordion').activate('activate',117);

I've tried those and some variations but can't get it to go. In the case I was trying to get working, the accordion should've opened to the end of the second section.

A: 

Try

$('#accordion').activate('#item117');

or

$('#accordion').actiavate(document.getElementById('item117'));

The correct syntax for activating an accordion is

$(".selector").activate(var index)

where index is String,Element,boolean,Number,JQuery

Saeros
+1  A: 

You need to call it using the function called accordion:

// Open the third set (zero based index)
$('#accordion').accordion('activate', 2);

To open a section containing a specific element, you would do something like this. Note: you need to target the trigger that normally opens and closes the section. In the docs this is an h3 element, your trigger element may be different, so change this accordingly.

$('#accordion').accordion('activate', '#accordion > div:has(#item117) > h3');
Doug Neiner
A: 

I'm still not getting this, so maybe I'm doing something else wrong as well. I've stripped it down to an example page here: http://www.ofthejungle.com/testaccordion.php Please have a look at it and its source.

eflat
A: 

Saeros ,

What is $("selector") ? because , i have a probleme to put the index in hidden field . My code :

$(document).ready(function() { $('#accordion').accordion({ active:2, collapsible:true, icons: { header: 'ui-icon-circle-arrow-e', headerSelected: 'ui-icon-circle-arrow-s' }, change: function(event, ui) { //selecDiv = document.getElementById(''); //getter //var active = $('#accordion').accordion('option', 'active'); //alert('Alert 1 : ' + active); alert($('#accordion').accordion('option', 'active')); } }); });

but the alert is always 2!

headache !!

John

John
A: 

I had the same problem with activating an accordion with #id. Sadly I hadn't found a way to this, so I've created a hack. I iterate through div elements in my accordion in order to get the index of interesting div. It looks like this:

acc = 'tab-you-are-interested-in';

// find corresponding accordion
act = 0;
panels = $('#accordion-element > div');
for (i=0; i<panels.length; i++) {
    if ( panels[i].id == acc ) {
        act = i;  
    }
}

$('#accordion-element').accordion('activate', act);
delphiak