I have a table that is generated via ajax and a certain column generates a link. As it was implemented, it currently writes a html with javascript intrusive. Something like below:
return "<a href=\"#\" id=\"detalhe-nota-" + record.data.id + "\" class=\'modal-detalhe-nota\' onclick=\"exibirModalDetalheNota(" + record.data.id + ")\">" + value + "</a>";
The html generated exits something like:
<a href="#" id="detalhe-nota-80549984" onclick="exibirModalDetalheNota(80549984)">23628</a>
I would like to bind the click
event to this link by its id attribute, but since the id is dynamic I do not know how to do it. An alternative with jquery would use the # modal-detalhe-nota
, as below:
$(document).on("a.modal-detalhe-nota", "click", function(e) { });
As I understand the elements are dynamically created, they should have their events linked in this way and not as below:
$("a.modal-detalhe-nota").on("click", function(e) {});
I have two questions:
- How to link the event with the id attribute?
- How to pass a parameter to the function? For this id that is dynamically generated is a parameter.