0
Html page:
<html>
<head>
</head>
<body>
<span id="resposta1"><a style="cursor:pointer" onclick="resposta(1)">Responder</a></span>
</body>
</head>
</html>
The following is, I have this javascript function that makes an ajax request when my link with class ". btn-reply" 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(button) 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 is loaded, I don’t know how to make my js ajax function capture the event from this button when it appears. Does anyone have any solution to this problem?!
Place the code instead of the image.
– DaviAragao
When you click on this other link that renders this button, you came to use the browser feature of inspecting code to check if the html of the button was inserted into the skeleton of the page?
– Fábio Jânio
Yes, I inspected it. The code is usually embedded into the page skeleton.
– Müller Espósito
Related: http://answall.com/questions/23970
– ptkato