In jQuery mobile app, I want to display the result from a web service in a list. How to create a list dynamically?
var arr = ["list", "items", "here"]; $("div").append("<ul></ul>"); for(var i in arr) { var li = "<li>"; $("ul").append(li.concat(arr[i])) }
Even better,
$.each( a , function(i,v) { $("#target_id").append("<li>" + v + "</li>") ; } ) ;
Where a is an array of objects for the contents of the list, i is the index variable passed to the jQuery.each callback function ( $.each ), and v is the value of this index.
a
i
jQuery.each
$.each
v
For reference: http://api.jquery.com/jQuery.each/ .