views:

2445

answers:

2

Hi,

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 ive 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?

A: 

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.

jfrobishow
+15  A: 

I haven't tested it, but this should probably work: Say that you have your accordion with id #accordion

$('#accordion').append('<h3><a href="#">New Paragraph</a></h3><div><p>New data</p></div>')
    .accordion('destroy').accordion();

Basically, just destroy and re-create the accordion.

Jimmy Stenke
Nice, tested at http://jsbin.com/ifaju
jfrobishow
Googled this for about ten minutes before thinking of looking here.
toast
Thank you - that did the trick for me. One question though! I am adding a section dynamically but when I re-create the accordion it opens the first section again. Is there any way I can stop it from doing that, and kept the previously expanded section?Thanks again.
DanyW