0
I have a little problem here, and this is it. I have a timeline that displays some posts, by ajax I load more content and make an append, the new items that are displayed do not catch the slideToggle. I manually added the script again on the page that is sending the content by ajax and the slideToggle works, the problem is, when it opens, it already closes quickly and does not leave the div in display, does anyone know how to solve ? I already put None display and did not solve.
$("#maisPostagens").click(function (event) {
event.preventDefault();
$("#carregando").toggle();
var posts = $(".postagens:last").attr("lang");
if (posts) {
var url = '_funControllers/exibePostagensLinhaDoTempo.php?posts=' + posts;
setTimeout(function () {
$.get(url, function (dataReturn) {
$("#carregando").toggle();
$(".auto").append(dataReturn);
});
}, 1000);
}
});
//efeito de aparecer e esconder divs de Comentários
$(".auto .postagens .comentarios .linkComentario").on("click", function (event) {
event.preventDefault();
$(this).parents('.externa').find('.comentarioPost').slideToggle();
});
Thank you
It is probably the way you are adding the event to the elements, it should add when the page is first loaded to all the elements that exist in it, then when your ajax runs and new elements appear those do not have the event. To tidy up or you replay the addition of the event after the ajax runs, or change the way the event is added to the event (having lifespan while the page lasts).
– Luis Henrique
Thanks Luiz, how do I make the code last even after the append ?
– Bruno Luiz