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
Post a Comment