I am building a reply system like on facebook where user can reply to another user's comment
So I have this jquery code that loads a new reply above an existing list.
$(".send-comment").on('keypress',function(event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13') {
var table = $(this).closest("table");
var commenttext = $(this);
$.ajax({
url: '/newcomment',
type: "POST",
data: {
comment: $(commenttext).val(),
},
success: function(response) {
$(response).insertAfter(table);
$(commenttext).val("");
}
});
}
});
Problem is the $(".send-comment").on('keypress',function(event) {...})
doesn't effect on the new content loaded with ajax while the other events work on it like this one
$(document).on("click", ".see-replies", function(e) {...})
that I use to see replies list.
I tried this two versions but nothing works
$(document).on('keypress',".send-comment",function(event) {...})
$(document).keypress(".send-comment",function(event) {...})
$(".send-comment").keypress(function(event) {...})
Thank you in advance for the help.