I am appending data to a table from an API call with jQuery. What i want to do now though is if someone clicks on a row in the table i want to pass the id of the row to another screen (edit screen) to edit the details of the row. When i try to add a click function to the row though it breaks as in the table doesn't populate with the data. what i've tried
option 1
$.get(...){
$.each(res.data, function (index, value) {
$(".TData").append('"<tr id="'+value.id'"><td>'+value.description+'</td> <td>'+value.order+' </td> </tr>"')
})
}
$(".TData tr").click(function(event){
console.log(event.id); <- doesn't return value.id
(in reality this will redirect to the next page passing the id)
})
and in line assignment of onclick
$.get(...){
$.each(res.data, function (index, value) {
$(".TData").append('"<tr onclick="rowClick(e)" id="'+value.id'"><td>'+value.description+'</td> <td>'+value.order+' </td> </tr>"')
})
}
function rowClick...
neither of these approaches worked, in that the table didn't populate with option 2. and under options 1 the id is never pushed into the console to do anything with. can someone explain what i'm doing wrong? }