Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7843211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:29:59+00:00 2026-06-02T16:29:59+00:00

I have a page of user comments. $(p).click(function(){ $(this).hide(200); }); When user clicks on

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:30:01+00:00Added an answer on June 2, 2026 at 4:30 pm

    You need to use .on() with selector parameter (the second argument):

    $(document).on('click', 'p', function() {
       $(this).hide(200);
    })
    

    I can’t see your markup, so I can’t tell what is the closest parent to p, but substitute document to the closest parent of p, so for example your markup is:

    <div id="bla">
       <p>...</p>
       <p>...</p>
       <p>...</p>
    </div>
    

    You’d write that as

    $('#bla').on('click', 'p', function() {
       $(this).hide(200);
    })
    

    From docs:

    When a selector is provided, the event handler is referred to as
    delegated. The handler is not called when the event occurs directly on
    the bound element, but only for descendants (inner elements) that
    match the selector.

    Delegated events have the advantage that they can process events from
    descendant elements that are added to the document at a later time. By
    picking an element that is guaranteed to be present at the time the
    delegated event handler is attached, you can use delegated events to
    avoid the need to frequently attach and remove event handlers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I have a list of user comments on a page, with a next
I have a blog post page with comments. Any user (logged in or not)
I have the following models: User: hasOne Profile, Page hasMany Comment Comment: belongsTo User,
I need something simple; I have page where a user clicks an author to
I have a web page that displays comments, and users can click a 'Flag'
I have a paging system implemented for user comments and depending on which page
I have some code which retrieves user comments from my database: $comments = mysql_query(SELECT
I have page where user upload they file to my web server which get
I have a page where user dynamically add search condition(s) to filter out records.
I would like to have the page on user/sidebar on the right in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.