I update pagination with ajax. Once the pagination is update with ajax, jquery doesn't respond to clicks any more.
How do I make jquery recognize the new added elements?
Here is my js code:
$(document).ready(function () {
$(".page").click(function () {
$.ajax({
url: '/ajax_request',
type: 'POST',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
"page": page,
}),
success: function (response) {
$('#main_table').find("tr:not(:nth-child(1))").remove();
const pagination_div = $('div.pagination');
pagination_div.empty()
let html = '';
$.each(response['pages'], function (indx, value) {
html += '<a class="page" id=' + value + '>' + value + '</a>'
})
pagination_div.html(html);
}
})
})
})