7
I have a table that is generated via ajax and a certain column generates a link. As it has been implemented, currently, it writes a code 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 comes out something like:
<a href="#" id="detalhe-nota-80549984" onclick="exibirModalDetalheNota(80549984)">23628</a>
I would like to link the event click
to this link by its id attribute, but since id is dynamic I don’t know how to do it. An alternative solution with jquery would be using the markup css modal-detalhe-nota
, as below:
$(document).on("a.modal-detalhe-nota", "click", function(e) { });
From what I understood by the elements to be created dynamically, they should have their events linked in this way and not in the form below:
$("a.modal-detalhe-nota").on("click", function(e) {});
I have two doubts:
- How to link the event to the id attribute?
- How to pass a parameter to the function? Because this id that is generated dynamically is parameter.
I’ve done something like that. I remember that at the time I used only onclick passing the value I needed to the method. + 1 good question.
– Marconi
@Marconi, I’m looking for a way to do with non-intrusive javascript.
– Philippe Gioseffi