I have some list tag in my HTML page .I want to find the text and id of list tag separately. Since my list is created in the run time so I cant figure out how to get the id and text value.
I have tried this
$("#users li").click(function(e)
{
console.log($(this).text());
console.log($(this).id);
});
But it is not triggering any click event.
HTML part
<div class="card card-body bg-light">
<h3>Online Users</h3>
<ul class="list-group" id="users"></ul>
</div>
jquery part
$(function () {
var socket =io.connect();
var $users =$('#users');
socket.on('get users',function(data){
var html='';
for(var i=0;i<data.length;i++){
html+='<li class="list-group-item" id="'+i+'">'+data[i]+'</li>';
}
$users.html(html);
});
$($users).click(function(e)
{
console.log($(this).text());
console.log($(this).id);
});
}