I have created with javascript a class called userChat, I would like to be able to add a click event handler to the userChat class so that when I click on userChat it will send me the name of the user I am clicking on, the problem is that I add an addEventListener but it doesn't It works, I don't know what I'm doing wrong, could you please help me, thank you very much.
function updateUsers(socket){
socket.on('updateUsers',function(data){
let usuarios = document.querySelector('#usuarios');
usuarios.innerHTML='';
for(let i = 0; i < data.users.length; i++){
let us = `<div class ="userChat">` +data.users[i] +`</div>`;
usuarios.innerHTML += us;
let userchat = document.querySelector('.userChat');
userchat.addEventListener('click',function(){
console.log('estas tocando al usuario: '+data.users[i]);
});
}
});
}