I'm trying to dynamically add elements to an accordion. Each added element contains a form with radio buttons styled with Custom Form Elements. Here is the code I'm using to add the element to the accordion.
$("#addpage").click(function(){
$.get("addpage.php", function(data){
$(data).insertAfter(".accordion div#[id^=element]:last");
});
$(".accordion").accordion('destroy');
callAccordion();
});
The code is added without issue, however, the accordion never completes and the buttons aren't styled. The error says Uncaught TypeError: Cannot read property 'style' of null. When I remove the radio button, the accordion works without issue.
Here is the code for callAccordion
function callAccordion(){
$(".accordion").accordion({
active: false,
autoheight: false,
collapsible: true,
alwaysOpen: false,
header: '> div >h3'
}).sortable({
axis: "y",
handle: "h3",
stop: function(event, ui){
stop = true;
},
update: function(event, ui){
var result = $(".accordion").sortable('toArray');
stop = true;
$.ajax({
type: 'post',
data: "element=" + result,
url: 'modules/updatepageorder.php',
success: function(data){
if(data != "true"){
alert("Unable to update page order!");
}
}
});
}
});
}