I am learning about nodejs + express + socket.io. I have a list of user list, list get append automatically when clients are connected. For making trial I have checked with click event with div element.
client side
<div class="userlist">
<ul>
............... ...............
</ul>
</div>
<script>
$('.userlist').click(function() {
socket.emit('private', 'test');
});
socket.on('private', function(mesg) {
$('body').append($('<li class="listm">').text(mesg));
});
</script>
server side
io.on('connection', function(socket){
socket.on('private', function(mesg)
{
console.log('private test message');
io.socket.emit('private',mesg);
});
});
But it does not work. when I click div it is not print the message in console also it will not append any text.
what did I wrong?