I am populating jQuery accordion from simple xml file, I can get my data and append it as html to simulate accordion markup. Then I call for accordion, it won't work!
I guess the problem is binding newly created data to DOM, I have tried .live() and .delegate with no success.
How should I proceed?
Here is simplified example of my code (sorry that some of the names and comments are in finnish :-)) here is the link http://www.equstom.fi/hanuri.html
$('#valitsija').click(function() {
$.get('http://www.equstom.fi/kurssit.xml', function(data) {
$('#accordion').empty();
$(data).find('Kurssi').each(function() {
var $kurssi = $(this);
var html = '<div>';
html += '<h3><a href="#">' + $kurssi.find('KurssinNimi').text() + '</a></h3>';
html += '<div>' + $kurssi.find('KurssiKuvaus').text() + '</div>';
html += '</div>';
$('#accordion').append($(html));
});
});
});
/* ********** haetaankurssit loppu ****** ******/ // Accordion $("#accordion").accordion({ header: "h3" });
http://www.equstom.fi/hanuri.html
I wrote an XML to jQuery Accordion utility last night and I thought I'd share it with you all here. Any feedback is appreciated.
http://lytsp33d.com/xml-to-jquery-accordion/
Best regards, Zach
Note the two lines below I added (with comments). You need to destroy and then recreate the accordion.
I would suggest storing the #accordion into a variable so you don't have to keep searching for it. This is called caching. (I know its not your question, but figured I'd offer this suggestion anyways). Something like this:
Proof that it works