html page:
<html>
<head>
</head>
<body>
<span id="resposta1"><a style="cursor:pointer" onclick="resposta(1)">Responder</a></span>
</body>
</head>
</html>
It is as follows, I have the this javascript function that makes an ajax request when my link with the ".btn-response" class is clicked:
$(document).ready(function(){
$(".btn-resposta").click(function(evt){
evt.preventDefault();
var idtop = $(".topico").attr("name");
var idpost = $(this).attr("name");
var texto = document.getElementById("textoresposta").value;
$.ajax({
type:"POST" ,
url:"lib/enviapost.php",
data:"idtop="+idtop+"&texto="+texto+"&idpost="+idpost,
beforeSend: function(){
},
success: function(data){
$(".posts").html(data);
}
});
});
});
The problem is that my link with this class is only rendered on the dps screen that the user clicks on another link that calls a js function that renders an html code with my button:
function resposta(idpost) {
document.getElementById("resposta" + idpost).innerHTML =
' <textarea id="textresposta' + idpost + '" rows="1" name="resposta" cols="30" onkeydown="ver(' + idpost + ')"></textarea> ' +
' <a name="' + idpost + '" id="btnresposta' + idpost + '" type="submit" class="btn btn-success btn-sm btn-resposta">GO</a> ';
}
As my button is rendered after the page loads, I do not know how to do it for my js ajax function to capture the event of this button when it appears. Does anyone have any solutions to this problem?!