1

I have a code

 socket.on('user joined',function(data){
       var ume = data.username;
        $('#userlist').append("<li id='"+ume+"'><a href='#' onclick='prePrivate("+ume+"); return false;'>"+ume+"</a></li>");
        console.log(ume);
 });

and prePrivate method

  function prePrivate(userprivate){
        privateuser = userprivate;
        console.log(privateuser);
  }

When i click li element, console print

<li id="sample_data">

but not print sample_data. I do not understand, how to get variable. Sorry my english not good

CodeGodie
  • 12,116
  • 6
  • 37
  • 66
bulubuloa
  • 597
  • 1
  • 10
  • 21
  • example: ume = "hoang" , i want console print hoang, but console print
  • – bulubuloa Mar 31 '15 at 02:59
  • 1
    you need to add quotes around `ume` in the string where you call prePrivate onclick: `...onclick='prePrivate(\""+ume+"\"); ...` – sebnukem Mar 31 '15 at 03:31