javascript - Dynamically add items to Listview in jQuery Mobile -


i'm having bit of trouble dynamically adding items listview in jquery mobile. want whatever input user in textbox added list. have following code , can not figure out why desired output not appearing.

<script>   var listcreated = false;   function appendtolist() {     if(!listcreated) {       $("#items").append("<ul id='list' data-role='listview' data-inset='true'></ul>");       listcreated = true;       $("#items").trigger("create");     }     $("#list").append("<li>");     $("#list").append(document.getelementbyid(item).value);     $("#list").append("</li>");     $("#list").listview("refresh");   } </script> <div data-role="content">   <div id="items"></div>   <input type="text" id="item" />   <input type="button" value="add item list" onclick="appendtolist()"/> </div> 

try creating entire li appending, right now, you're appending opening <li> list, value list, not new li

var value = $("#item").val(); var listitem = "<li>" + value + "</li>"; $("#list").append(listitem); 

demo: http://jsfiddle.net/dvbgy/1/


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -