I have a page of user comments.
$(p).click(function(){
$(this).hide(200);
});
When user clicks on some comment this one usually disappears. Ok it works perfectly.
But when user does the same with server response, this does not work anymore
Server response is a bunch of next comments found in table (i.e custom AJAX paginator)
Server response looks like this:
<p id="next-id1">bla bla bla 1</p>
<p id="next-id2">bla bla bla 2</p>
Then this response inserts content after particular div which contains first comments in mysql table
like this:
$("#snow-next-btn").click(function(){
$.post('/paginator.php', {}, function(response){
$("#comment-div").after(response);
});
});
Ok it works perfectly as I said. BUT this method:
$(p).click(function){
$(this).hide(200);
}
does not work with server response anymore (but it still works with contents that has been printed by php on page load).
Where is the problem?
You need to use
.on()withselectorparameter (the second argument):I can’t see your markup, so I can’t tell what is the closest parent to
p, but substitutedocumentto the closest parent ofp, so for example your markup is:You’d write that as
From docs: