Reputation: 553
I am trying to add a collapsible DIV with the JQuery mobile CSS dynamically to a page.The list of DIVs and the associated content is populated in a for loop.
items.forEach(function (entity) {
document.getElementById("auditListHolder").innerHTML = document.getElementById("auditListHolder").innerHTML +
"<div data-role='collapsible' data-collapsed='false'>" +
"<h3>" + entity.AuditName + "</h3>" +
"<p>" + entity.Content + "</p>" +
"</div>";
});
I tried using this code to add a DIV to existing set of DIVs on each iteration of the loop, but the DIV does not render as a collapsible DIV. The list appears as normal DIV with content as shown below:
Is there a problem with the code or can there be problem with CSS.
Upvotes: 1
Views: 913
Reputation: 31732
Call widget enhancement .collapsible();
after appending elements dynamically.
$('selector').collapsible();
selector =
[data-role=collapsible]
,#id
,.class
etc...
Upvotes: 1
Reputation: 2126
Try calling .trigger("create") on the element auditListHolder after the loop!
Upvotes: 1