Several questions here on SO reference this open jQuery UI feature request for the ability to dynamically add/remove panels from the Accordion widget. The ticket itself is marked (closed feature: fixed) and from what I can tell from the unit tests and a pull from their Git repository it appears to be implemented in the latest release.
However if I try to add a div like they did in the unit test above:
var element = $("#accordion");
$("#accordion").append("<h3>3</h3><div>3</div>");
$("#accordion").accordion("refresh");
I can't get it to work.
However this method works:
$("#accordion").append("<h3>sec</h3<div>test</div>").accordion("destroy").accordion();
But I don't want to "destroy" the accordion, I just want to append (or prepend) an element and refresh it.
Looking at the div I added in Chrome's inspector shows that the element I added doesn't have the same CSS styling added as the rest of the accordion:
Actually discussed behaviour was included in jQuery UI 1.10.0 (just released) and works fine for me.
Thanks to Jarek! In my case is it functional without enclosing div. The div causes creating next accordion.
unibasil is correct that jQuery UI 1.10.0 has updated the refresh method to now allow this behavior.
Here's the 1.10.0 changelog note about the update.
Setup
Javascript
Example
jsFiddle showing that you can add new accordions on the fly without having to destroy the old one.