I have the following situation, I am loading a code from Php to html with jquery . What is happening to me is that from the code I'm printing from Php when I show it in the html I do not recognize the jquery selector ( a.deleteComec ) that I'm printing from Php . Then I leave the code to see if you can help me. Thank you.
Php code
foreach ($datos as $val){
if($usuario == $val['idusuario']){
echo '<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title" >'.$val['nombre']." ".$val['fechahora'].'<div class="text-right"><a class="deleteComec" id="'.$val['id'].'" href="#" title="Borrar">Borrar</a></div></h3>
</div>
<div class="panel-body">'.
$val['comentario']
.'</div>
</div>';
}else{
echo '<div class="panel panel-warning ">
<div class="panel-heading">
<h3 class="panel-title" >'.$val['nombre']." ".$val['fechahora'].'<div class="text-right"><a class="deleteComec" id="'.$val['id'].'" href="#" title="Borrar">Borrar</a></div></h3>
</div>
<div class="panel-body">'.
$val['comentario']
.'<div>
</div>';
}
}
Upload the content to the html with jquery
var cargarmensaje = function(){
idcoment = $("input#id").val();
$.post("index.php?c=pendientes&f=getcomentario",{id: idcoment},function(data){
$("#listcomentario").html( data );
});
}
Where the selector runs (a.deleteComec)
$('a.deleteComec').on("click",function () {
id = $(this).attr('id');
bootbox.confirm("Está eguro que desea borrar. Recuerde que al borrar, se eleminaran todos los datos asociados en Cascada", function (result) {
if (result) {
$("div#idloader").addClass("loader");
$.post('index.php?c=' + a_id[1] + '&f=delComec', {id:id}, function (data) {
cargarmensaje();
$(".loader").fadeOut("slow");
});
}
});
});
As the code is displayed in the browser
<a class="deleteComec" id="144" href="#" title="Borrar">Borrar</a>