开发者

How to stop a jQuery accordion change event when recreating it?

I have three different accordions in three different dom elements, when I move one accordion section to another accordion section programmatically on a click of move button, I'm recreating all the accordions on the page. I want the selected accordion to be opened/expanded in the moved accordion. But the moved accordion is sometimes collapsed and other times expanded. I think this is happening because 开发者_高级运维after recreating the accordion, it fires the change event and becomes collapsed.

Can any one suggest a solution how to stop that accordion change event after recreating the accordion. I'm already using the suggestion in this post


Store the accordion options in a variable so you can use it over and over again. Then, when you destroy the accordion, set which pane you want open/active (integer):

accord_options.active = 3; // This is the number value of the accordion pane you want open. Accordion panes start at 0.
$selector.accordion('destroy').accordion(accord_options);

If you need further control over when the accordion fires, you can use an empty event in the accordion options:

accord_options = {
    event: '',
    ...

Then create a function to handle accordion clicks:

$('#accordion_1 h3').click(function()
{
    if (something_happens)
    {
        // we don't want the accordion to activate here
        return false;
    }

    // to activate an accordion pane:
    $selector.accordion('activate', $('#accordion_1 h3').index(this));

    return false;
}

Add your own code to the above click method to handle whether or not you want an accordion pane to activate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜