In the code below i'm trying to run a function screw(); giving it the value of the span as a parameter to use
socket.on('usernames', function(data) {
var html ='';
for(i=0; i< data.length; i++){
html += '<a><span onclick ="screw(data[i]);" style="font-weight: bold; cursor:pointer;">' + data[i] + '</span></a><br/>'
}
$('#online').html(html);
});
Please note that the "data" parameter being passed into the above function is an array automatically generated on the server side
here is the "screw" function in action. Im trying to at least alert the value it gets
function screw(vem){
alert(vem);
}
But i keep getting that a reference error that data is undefined. Please can you spot what i'm doing wrong?'
datalooks like please?codevar users = {}; socket.on('new-user', function(data, callback){ if (data in users){ callback(false); }else{ callback(true); socket.usernames = data; users[socket.usernames] = socket.id; update(); } }); function update(){ io.emit('usernames', Object.keys(users)); }codecodehtml += "<a><span onclick ='screw(\""+data[i]+"\");' style='font-weight: bold; cursor:pointer;'>" + data[i] + "</span></a><br/>"code