Currently I have static html table in bootstrap 4 modal window. When page opens, I fill the table with some data that I have retrieved with ajax get call from server.
On success I am wrapping my data in
<td>
and<tr>
tag and appending whole structure to my<tbody>
of the table. Now, one of the things I have added to my table is some<a>
link. I want to refer somehow to that element. More precisely, I am trying to create some event handler but unsuccessfully, it doesn't workHere are some snippets from code, first is event handler in jQuery, second is my function which retrieves data and builds my
tbody
content dynamically.
I tried to google this case but without luck, hope someone can help.
$("#deleteLink").on(click, function() {
var idVersionNote = this.attr("data-note-id");
deleteVersionNote(idVersionNote);
});
function getNotes(idVersion) {
var url = /*[[@{/notes/getNotes/}]]*/ '';
url += idVersion;
$.ajax({
url: url,
dataType: 'json',
type: 'get',
cache: false,
success: function(data) {
/*console.log(data);*/
var append_data = '';
$.each(data, function(index, value) {
/*console.log(value);*/
append_data += '<tr>';
append_data += '<td>' + value.user.loginUser+ '</td>';
append_data += '<td>' + value.versionNote.tstampCreation+ '</td>';
append_data += '<td>' + value.versionNote.tstamp + '</td>';
append_data += '<td>' + value.versionNote.note + '</td>';
append_data += '<td><a href="#" id="deleteLink" data-note-id="' + value.versionNote.idVersionNote + '"">Delete note</a></td>'
append_data += '</tr>';
});
$(".notesTable tbody").append(append_data);
},
error: function(d) {
/*console.log("error");*/
alert("Error");
}
});
}