1

This is a seemlingly simple question, but I'm wracking my brain trying to figure this one out.

I have a JQuery accordion on my page.

I'm writing a client-side script to find a specific node based on a parameter passed through a querystring. This code finds me the specific node in the accordion:

$('.accordion').find('.nodeclass');

Question - how do I deactivate all the other nodes in the accordion and expand only the one passed through the querystring parameter?

2
  • Is it jQueryUI's accordion? If so, expanding one section should collapse the rest. Feb 20, 2012 at 16:16
  • Yes, it's a JQueryUI accordion. I'm looking for the script to expand the node I've found in my sample script. (I find the node, but I've tried both toggle() and activate())
    – Tim
    Feb 20, 2012 at 16:17

2 Answers 2

0

If you need to close all the nodes of the accordion (i'm guessing here) you need and then open only one you must do

//close all
$('.accordion').accordion('activate', false);
//open one
$('.accordion').accordion('activate', idxofaccordion);

where idxofaccordion is the index (0 based) of the accordion you want to open. In the demo page look under "methods" for reference.

You could also try to select just one without clasing all the panels before, it might work

1
  • The nature of the accordion is to only have one section open at a time. I don't think the 'close all' call is necessary. Also, you can pass a selector to activate which might be more relevant to the question. Feb 20, 2012 at 16:22
0

Figures after I post the question I wound up figuring it out...I can attach a click() handler and simulate a mouse click on the node.

1
  • 1
    you should use the API instead of simulatin a click Feb 20, 2012 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.