I get data from a JSON file and then show it using the html structure following the jquerymobile structure with the data role, etc. Here is my code on how I get the data and display it:
$(document).on('pageinit', function(){ $.getJSON("http://danielvivancos.com/edu/wordpress/?json=get_posts&post_type=product", function(data){ var html = ""; $.each(data.posts, function(index, d){ html = html + "<li><a href='" + d.slug + "' data-transition='slidedown'><img src='" + d.thumbnail_images.thumbnail.url + "' /><h3 class='ui-li-heading'> Menu" + index + "</h3></a></li>"; }); html= "<ul data-role='listview' data-inset='true'>"+ html + "</ul>"; $(html).appendTo(".choice_list"); }).error(function(jqXHR, textStatus, errorThrown){ alert("error occurred!"); }); });
The result in HTML is as follows:
<li><a href="link1.HTML" data-transition="slidedown"> <img src="source1"><h3> Menu1</h3></a></li> <li><a href="link2.HTML" data-transition="slidedown"> <img src="source2"><h3> Menu2</h3></a></li> <li><a href="link3.HTML" data-transition="slidedown"> <img src="source3"><h3> Menu3</h3></a></li>
But my problem is that although I display the content as jquerymobile says, the style that should be applied is not. I mean that all classes added by jquerymobile script are not added to my html generated using javascript. Does anyone know how I can fix this? How to save styles from jquerymobile? Thank you so much for the promotion!
ANSWER:
$(html).appendTo(".choice_list").listview();
source share