jQuery Mobile loading accordion dynamically not functioning
I am loading the jQuery Mobile accordion dynamically via JavaScript and having it create the elements and inject the HTML into the page. Now when I do this, I don't get the styles, I don't get the theme and I don't get the functionally. It basically does not work. Does anyone know why it is doing this? let me know if you need anymore info.
- $('#film').attr({'data-role': 'collapsible-set', 'data-theme': 'c', 'data-content-theme': 'd'});
- var sort_by = function(field, reverse, primer){
- var key = function(x) {return primer ? primer(x[field]) : x[field]};
- return function(a,b) {
- var A = key(a), B = key(b);
- return ((A < B) ? -1 : (A > B) ? +1 : 0) * [-1,1][+!!reverse];
- }
- }
- $.ajax({
- type: 'GET',
- url: 'list',
- async: false,
- jsonpCallback: 'fl',
- contentType: 'application/json',
- dataType: 'jsonp',
- success: function(data) {
- var tmp = [];
- for(var i=0;i<data.nodes.length;i++) {
- tmp.push(data.nodes[i].node);
- }
- tmp.sort(sort_by('title', true));
- var div = document.createElement('div');
- $('#film').append(div);
- $(div).attr( 'data-role', 'collapsible' );
- var heading = tmp[0]['title'][0];
- var h3 = document.createElement('h3');
- h3.innerHTML = heading;
- $(div).append(h3);
- h3=null;
- var title = '';
- for(var i=0;i<tmp.length;i++) {
- if(tmp[i]['title'] != title){ title=tmp[i]['title'];
- if(tmp[i]['title'][0] !== heading){
- heading = tmp[i]['title'][0];
- var div = document.createElement('div');
- $('#film').append(div);
- $(div).attr( 'data-role', 'collapsible' );
- var h3 = document.createElement('h3');
- h3.innerHTML = heading;
- $(div).append(h3);
- h3=null;
- }
- var p = document.createElement('p');
- p.innerHTML += "<a>"+tmp[i]['title']+"</a>";
- $(div).append(p);
- p=null;
- }
- }
- }
- });