While loading the page I get DB data and create a list as below.
function chatContactList() {
$.post('src/inc/chat/', { DataProcess:'chatContactListShow' }, function(data){
switch(data.status) {
case 'error':
sNoty(data.message, null, 'error', null);
break;
case 'noHasList':
return false;
break;
case 'hasList':
var content = ''
$.each(data.chatOBJ, function(index, value){
content += '<li>';
content += ' <a href="#" data-process-id="'+value.pr_id+'" id="chatByContact" class="chatByContact">'+value.userName+'<i class="fa fa-comments"></i></a>';
content += '</li>';
});
$("#ulSidebarMenuContact").html(content);
break;
case 'logOut':
case 'reload':
window.location.reload();
break;
}
}, 'json');
};
After loading the data and creating the list, I need to get the attribute data-process-id, no click event, and do constant update, but I do not get any attribute.
function updateMessageNotRead()
{
var prIdArray = new Array();
$('a[id="chatByContact"]').each(function() {
prIdArray.push($(this).attr('data-process-id'));
});
...
}
How to get this attribute created automatically and without delegating to event like click?