I have a small code, that responsible for drawing newly added comments. THe problem is, when i rewrote code to use on
instead of removed live
, my code doesnt work on new elements, that were added after page load
Here is my code
$(function(){
$('.show-comment-form').on("click", (function(){
dataattr = $(this).data('comment');
$('#new_comment').remove();
$('.message-'+dataattr).append(partial_form);
$("#comment_parent_id").val(dataattr);
return false;
}))
})
HTML
<a href="/phrases/52/create_comment?parent_id=16" class="show-comment-form" data-comment="16">Reply</a>
How do i add click event to all future elements, that will be added after page load?