Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile creating a Collapsible set dynamically via ajax does not apply styling [duplicate]

Possible Duplicate:
Dynamically adding collapsible elements

I am dynamically creating a Collapsible set and adding it to the page using $('#myID').html(htmlcode). The styling is not being applied to the page. How can I get jQUery mobile to apply it styling?

(I am using $.get() to query a web service.The content that returned I am looping through to create the markup)

like image 909
Dappy Avatar asked Aug 27 '11 23:08

Dappy


1 Answers

This is working for me. My ajax returns a bunch of h3's which I insert into a collapsible div and append a p tag for the content.

$(document).ready(function(){

    $.get(my_url, function(data) {
        var content = $('div[data-role="content"]').html(data);
        $('h3').each(function(h3_element) {
            var coll = $('<div class="ui-collapsible-contain" name="blog"  data-role="collapsible" data-collapsed="true">');
            coll.append($(this));
            coll.append($('<p>'));
            content.append(coll);
        });
        content.trigger( "create" );        
    });

});
like image 68
Bjorn Avatar answered Oct 12 '22 11:10

Bjorn