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

  • Home
  • SEARCH
  • 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 6625857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:49:27+00:00 2026-05-25T21:49:27+00:00

Although I have research this topic I don’t really seem to understand how to

  • 0

Although I have research this topic I don’t really seem to understand how to make it work.

Situation:

The following code is used to show the new_comments Div on my page.

<script type="text/javascript">
    $(function(){
        $('#lnk_comment').click(function() {
            //alert('Handler for .click() called.');
        $("#comment_new").show();
        $('#new_comment').focus();
        });
    });
</script>

This code works great when these div tags are generated by PHP.

The Problem:

If I instead query this PHP page through JQuery using the .get Method outputting the result using JQuery instead, it seems that the function above no longer works. It seems as though the click() event doesn’t seem to bind to the lnk_comment tag.

My Guess is that the DOM is loading first and the JQuery data is loading after.

The Question:

How do you add/bind a Click event to tags that have been generated through JQuery/JavaScript during run time?

Other Thoughts:

I have found something in regards to a .delegate function in JQuery but after numerous attempts, I don’t really seem to get it.

Thank you for any examples.

  • 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-05-25T21:49:27+00:00Added an answer on May 25, 2026 at 9:49 pm

    Use live() instead:

    <script type="text/javascript">
    $(function(){
        $('#lnk_comment').live('click', function() {
            //alert('Handler for .click() called.');
            $("#comment_new").show();
            $('#new_comment').focus();
            });
        });
    });
    </script>
    

    This will automatically bind the events to newly added DOM members that match the selector (in this case #lnk_comment).

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

Sidebar

Related Questions

Although i have specified a unique key, it seems the following code will return
I know I need to have (although I don't know why) a GROUP BY
I hope this is a relatively easy problem although I have spent hours websearching
Although I have no problem using SecureCRT (5.1.2 build 274) to work from Windows
I'm having trouble with this and, from the research I have done, I think
Although I have some experience in Android development, I don't have a lot of
Total n00b to C# and events although I have been programming for a while.
I am new to both Qt and Linux C++ development (although I have many
I'm already new in C++CLI , although I have been working on VB and
I use Delphi for many years, and although I have now moved on to

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.