views:

539

answers:

1

Hi, when I do :

$(#my-accordion).accordion('activate', N);

... to open a specific section of the accordion, the behaviour is not as expected. It does not 'activate' that section programmatically (force it to open). It simply toggles the Nth section of the accordion. Why on earth would they call this function 'activate' instead of 'toggle' ?!!!

Is there a way to programmably force a particular section to open. My accordion has collapsed:true. Any help appreciated...

=================

full code (simplified):

//links
$("a.morelink.ethos").click
(
    function()
    {
        loadSection("about");
        $('#accordion-about').accordion('option', 'active', 0); //activate simply toggles. don't use it!
        return false;
    }
);

function loadSection(section)
{
    //...blah blah blah
    $("#about-div").show();

}

And here is the structure of the panel:

<!-- about -->
<div id="panel-about">

    <!-- content area -->
    <div class="content about">
        <ul id="accordion-about">
            <li id="ethos">
                <p class="caption"><a href="#">Our core ethos</a></p>
                <div>Some content here</div>
            </li>
            <li id="history">
                <p class="caption"><a href="#">Our History</a></p>
                <div>Some content here</div>
            </li>
            <!-- more sections here.... -->
        </ul>
    </div>
</div>
A: 

Use the active option to choose which section(s) to make active.

$('.selector').accordion('option', 'active', N);
tvanfosson
I didn't know about this method. Thank you - I tried but it still does not work for me. the accordion is inside a div which is hidden. I click a link on my homepage which unhides the div with the accordion, and then executes the above option code, but when it finally displays it is still stuck on the previously open section, not 'N'...
rekindleMyLoveOf
Can you post the full code as amended?
tvanfosson
I've added a simplified ver of code to the questions. Also, I noticed directly typing 'activate' jquery code in firebug js console toggles the specified section, as expected, whereas typing the 'option' code directly does nothing. Hmm...
rekindleMyLoveOf
Your markup doesn't match the semantic expectations, i.e., a set of header/div pairs foran accordion. What does your accordion set up look like?
tvanfosson
tv, I'm going to just accept your answer because you taught me how to use 'option' method and also alerted me of my accordion headers poorly defined semantics. Incidentally I switched to default use of 'h3' as header tags, and realised that the 'active' call was always returning null, or the last set index; it never changes. I think it is a jquery UI bug as described here: http://dev.jqueryui.com/ticket/4576 (scroll to bottom). Thanks for all your help! :-)
rekindleMyLoveOf