Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

re-initialize jquery accordion on callback

I've got the accordion working fine on pageload, however upon user interaction with some elements on the page, I am using ajax to rebuild the HTML of the accordion. Then, I try to re-initialize the accordion again with

    $('#accordion').accordion({
        active: false,
        autoHeight: false,
        clearStyle: true,
        collapsible: true,
        header: 'h3'
    });

but... it doesn't seem to be taking.

The new block of rendered HTML isn't applying the accordion rules. Instead it just stays open as a large list.

I've even tried setTimeout() for re-calling the accordion just incase it was trying to initialize before the rendered HTML is returned in the callback.

The HTML that is rendered in the callback is the exact same as that of the pageload (with exception to the DOM additions that occur when the Accordion method is effective)

like image 568
aimlessWonderer Avatar asked Aug 19 '09 18:08

aimlessWonderer


1 Answers

Destroy the accordian before repopulating it with data.

$('#accordion').accordion('destroy');
like image 64
Stefan Kendall Avatar answered Nov 16 '22 02:11

Stefan Kendall