I use ajax to create dynamic div, and want to get notified when I click the "a" inside div which id='listall', but it's not working, why? How to correct it. thanks here is the code:
$(function(){
$.ajax({
type: "GET",
url: 'http://XXX:8080/',
dataType:'json',
contentType:"application/json",
success:function(data){
console.log(data);
var projectList="<ul style='list-style:none;'>"
for (var i = 0; i < data.data.length; i++) {
projectList += "<li><div id='listall'><a href='/projectDetail'>"+
"<img class='back' src='data.data[i]'></li>"
}
var projectList +="</ul>"
},
error:function(){
alert("connection error");
}
});
$('#listall').on('click', 'a', function (){
console.log('click!');
alert("finally");
});
});