I use query to build a mobile app. First of all I use $.getJSON to retrieve data from json file:
$.getJSON('js/sura.json', function(data){
$.each(data, function(key, value){
//alert(key+' '+value['id']);
buildList(value['id'], value['name'], value['number']);
});
});
There are more than 100 rows from json file.
After that, I need to put every lists to an elements name <ul id="list></ul>. Should I make new Javascript function then write the code:
function buildList(id, name, number){
var name_elm = '<h3>'+name+'</h3>';
var noq_elm = '<span>'+number+'</span>';
var $list_elm = '<li>'+name_elm+''+noq_elm+'</li>';
$('#list').append($list_elm);
}
After I use .append(...). I would like to add click listener to every lists (each list has unique id).
How should I write query to add listener to each <li></li>?