Hawiak
Hawiak

Reputation: 553

Accordion isn't loading in ajax called elements

I do got a nice accordion like the example over at JQuery UI and it works but when i refresh the div with an ajax call the accordion doesnt work anymore, its just plain html... How can i do this i searched the internet and i only get "How to load ajax into accordion" or I read that it isn't possible with .live() which i already found out.

I tried loading in after the ajax was finished, which looks like this: $("form.ajax").submit(function(){

    var url = $(this).attr('action');
    var element = '';
    if($(this).attr("element") != null)
    {
        element = $(this).attr("element");
    }
    else if($(this).attr("element") == null)
    {
        element = "render";
    }
    $("#"+element).html("<div id='loader'>Laden...<br /><img src=\"/site/templates/img/ajax-loader.gif\"/></div>");
    $.post(url, $(this).serialize(), function(data){
        $('#accordion').accordion();
        $("#"+element).html(data);

    });
    return false;
}); 

I don't think im the only one with this problem

Please help me out

Upvotes: 0

Views: 224

Answers (1)

user1329040
user1329040

Reputation:

You have to fill the div first, an then set the accordion. Like this:

$("#"+element).html(data);
$('#accordion').accordion();

Upvotes: 2

Related Questions