I am using the jQuery accordion plugin to make an accordion of some data. Then I want the user to be able to add more data to the accordian. I have setup the accordion to function properly, then I've made a function that prepends a "list item" to the accordion that matches the accordion semantics.
Is it possible to "update" the accordion so that it works with the newly added element, without saving the new data to database and refreshing the page?
Something like this:
.accordion('refresh')
Or something like the live event added in jQuery 1.3, anybody got a clue?
As mentioned above by Shahzad, jQuery UI 1.10 has made this easier; see the documentation.
To add a new section, and keep the old one active:
I haven't tested it, but this should probably work: Say that you have your accordion with id #accordion
Basically, just destroy and re-create the accordion.
UPDATE:
Since this answer was written a refresh() method has been added to the accordion widget. It can be invoked by calling:
You can read more about this method here
Since i needed a working add/edit/delete vor accordion items i hacked this little javascript functions for this purpose
http://jsfiddle.net/Sd6fC/
h3 and div need an unique id which goes by the following convention
the corresponding div need the following
sample accordion code block
have fun maybe it helps some ppl out there!
You might want to look at the LiveQuery plugin: http://plugins.jquery.com/project/livequery
It allows you to add events and binding after the DOM is loaded.