I have a comment system in which the user submits a comment, the comment is processed, then HTML is returned for the comment. jquery then adds that extracted HTML to the comment system. that the whole system works, but the comment buttons that require javascript do not work unless I refresh the page. How to make my work with javascript on elements added through loading, adding or adding?
Not sure if my question is clear, but here I have javascript:
$(function () { $(".replyform").submit( function (event) { event.preventDefault(); id = $(this).attr("id").split('_')[1]; text = $('textarea#text_'+id).val(); $.post( "/api/add/comment/", {_csrf: _csrf, id: id, text: text, a: a}, function (data) { $('#commentreplies_'+id).prepend(data); $('#replyform_' + id).hide(); }); }); });
Then I have elements such as a βresponseβ for each comment that has functions in external javascript that doesn't work if I don't refresh the page. Hope that made sense.
source share