I have written code in javascript the function searchCompany
queries the database and adds a list of applicant_original
and corresponding buttons to select them. The list and the buttons are created and visible in the UI but the event handler is unable to be attached to the button.
function searchCompany() {
$("#search-result").html('');
let res = [];
let name = $("#company_name").val();
$.ajax({
url: `http://localhost:5000/manualharmonization/query?name=${name}`,
success: function (data) {
data.map((el, i) => {
$("#search-result")
.append(`<tr class="list-item"><td>${el.applicant_original}</td>
<td class="elem-button"><button class="button" id="${i}"type="button">Select</button></td>
</tr>`);
});
},
error: function (e) {
console.log(e);
alert(JSON.stringify(e));
}
});
}
$("#search-company").click(searchCompany);
(function addClick() {
$("tr").map(i => {
$(`#i`).click(function () {
console.log("clicked");
})
})
})();
The addClick
function is not working. No button having id=i
logs when clicked.