Attached find a jfiddle showing injection of <li>
elements - the output in all ways is absent of the defined CSS - opposed to the hard coded <li>
's - why is that?
Asked
Active
Viewed 116 times
-7
-
1Please post the code. Here. – bfavaretto Apr 05 '13 at 19:11
-
7you didnt attach a jsFiddle. unless "find a jfiddle" is a challenge? – PlantTheIdea Apr 05 '13 at 19:11
-
1Since you didn't attach a fiddle, here's one demonstrating how to insert `
- ` and apply css style: http://jsfiddle.net/95v7q/1/
– tymeJV Apr 05 '13 at 19:14 -
Oops forget the link - but thanks for the good reply to Gajotres. [link] (http://jsfiddle.net/AXnKq/) – AndBB Apr 06 '13 at 07:28
1 Answers
2
Dynamically added listview elements must have its markup enhanced with this function:
$('#listviewID').listview('refresh');
Working example: http://jsfiddle.net/Gajotres/LrAyE/
In case you receive this error:
cannot call methods on listview prior to initialization
Then restyle your listview with this:
$('#listviewID').listview().listview('refresh');
First listview function will initialize listview and second one will restyle it. But do this ONLY if error mentioned earlier is shown.
One last thing, if you are using for loop or each loop to add numerous li element use listview('refresh') only after everything has been added to the ul element.
Read more about it in my other article/answer: jQuery Mobile: Markup Enhancement of dynamically added content, search for the chapter: Enhance a single component/widget.