Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  166] [ 4]  / answers: 1 / hits: 23884  / 13 Years ago, tue, february 14, 2012, 12:00:00

In the moment I can add li tags to my list with script. But how can I add dynamically li tags in a function in .js? Hopefully I will see a good example.
Below is my code. Thanks!



<div data-role=page id=searchPage data-theme=b>
<div data-role=content>
<ul data-role=listview data-filter=true data-theme=b id=searchListUl>
</ul>
</div>
<script type=text/javascript>
$(#searchListUl).append('<li data-filtertext=Apple><a href=#>Apple</a></li>');
$(#searchListUl).listview('refresh');</script></div>

More From » jquery

 Answers
29

Your function would be something like:



var addItem = function(item){
$(#searchListUl).append('<li data-filtertext='+item+'><a href=#>'+item+'</a></li>');
}


You can call it with:
addItem(apple)


[#87473] Monday, February 13, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aliah

Total Points: 118
Total Questions: 132
Total Answers: 94

Location: Tajikistan
Member since Fri, Sep 11, 2020
4 Years ago
;