Reputation: 2347
In trying to create a dynamic accordion with jquery, I can't figure out why the individual elements aren't collapsed. They just appear as text rather than taking on the accordion effect. Can anyone spot my mistake? (Assume that the data variables all contain data)
edit: I just tried it in firefox instead of chrome for curiosity's sake and the accordion behavior works..I don't get it
var outdiv = $('<div data-role="collapsible-set"></div>');
for(var i=0; i<data.length; i++){
var innerdiv = $('<div data-role="collapsible" data-collapsed="true" ></div>');
innerdiv.append('<h3>' + 'Tweet #' + i + '</h3>');
innerdiv.append('<p>' + data[i].text + '</p>');
outdiv.append(innerdiv);
outdiv.appendTo('#output');
}
Upvotes: 1
Views: 1248
Reputation: 1
Change your code to:
outdiv.append(innerdiv).collapsibleset("refresh");
You will have to download jQuery Mobile ver 1.3.2.
Upvotes: 0
Reputation: 92805
You need to call collapsibleset()
method on your outdiv
$('#output [data-role=collapsible-set]').collapsibleset();
Working jsFiddle here
Upvotes: 3
Reputation: 7811
I don't know if you can select a whole element this way or not, but you can also use jQuery's Attribute Contains Selector
//So your outdiv would become
var outdiv = $('div[data-role*="collapsible-set"]');
//And then innerdiv, something like
var innerdiv = $('div[data-role*="collapsible"][data-collapsed*="true"]');
Upvotes: 0