javascript - Dynamically add link with String parameter -


i have rest backend link mywebsite/guests, returns list of guests. in front end, want display guests links. here's code

for(guest of guests) {   $('#guest_list').append('<a onclick="showguest(' + guest.id + ')">' + guest.name + '</a><br>') }  function showguest(id) {   console.log(id)   ... } 

i should mention guest.id string.

the console print undefined. question, how can add these links string parameters?

for(guest of guests) {   $('#guest_list').append('<a onclick="showguest(this)" data-id='+guest.id+'>' + guest.name + '</a><br>') }  function showguest(this) {  console.log($(this).data('id')) } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -