Note the two lines below I added (with comments). You need to destroy and then recreate the accordion.
$('#valitsija').click(function() {
$.get('http://www.equstom.fi/kurssit.xml', function(data) {
//you need to destroy the accordion first
$('#accordion').accordion("destroy");
$('#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));
});
//you need to re-make the accordion
$("#accordion").accordion({ header: "h3" });
});
});
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:
$('#valitsija').click(function() {
$.get('http://www.equstom.fi/kurssit.xml', function(data) {
var acc = $('#accordion');
//you need to destroy the accordion first
acc.accordion("destroy");
acc.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>';
acc.append($(html));
});
//you need to re-make the accordion
acc.accordion({ header: "h3" });
});
});
pinkfloydx33
2010-10-30 04:32:01