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 6863303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:45:58+00:00 2026-05-27T02:45:58+00:00

Maybe you understood from the title however here I go: I have a file,

  • 0

Maybe you understood from the title however here I go:

I have a file, from that file I load some other data from a php file:

File 1 html file

<html>
     <head>
      <script type="text/javascript" src="js/jquery.js"></script>
      <script type="text/javascript">
          $(function() {
               $('#content').load('source.php');

               $("#link").click(function() {
                       alert('Message1!');
                       return false;
               });
          });
      </script>
     </head>

     <body>
           <div id="content"></div>
     </body>
</html>

File source.php

<?php

for($i=1;$i<=10;$i++) {

     echo '<a href="#" id="link">Link '.$i.'</a>';

}

?>

After the content is loaded from the php file now this code

$("#link").click(function() {
        alert('Message1!');
        return false;
});

doesn’t work for loaded content(links).

I need just an explanation how this DOM works, why loaded content can’t interact with active functions/codes?

  • 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-27T02:45:59+00:00Added an answer on May 27, 2026 at 2:45 am

    you just have to use live instead of click
    for example

    $("#link").live('click', function() {
            alert('Message1!');
            return false;
    });
    

    EDIT :

    I learned just now that it is deprecated since JQuery 1.7 so now we have to use .on() function like :

    $("#link ").on("click", function(event){
        alert('Message1!');
        return false;
    });
    

    http://api.jquery.com/live/

    http://api.jquery.com/on/

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

Sidebar

Related Questions

i am using jQuery to get some JSON data from a php file. my
So, maybe I've understood something wrong, because I'm from the SQL world: I have
From what I understand, the trade-off here is a matter of added complexity. Maybe?
Ok the title maybe a little confusing. I have a database with the table
I don't understand this at all. Here is some Javascript code that works in
i have understood that a namespace is a container of units; but i haven't
I have a Java module that receives the User-Agent string from an end user's
Not that it matters strictly, and maybe I just don't yet fully understand how
Maybe I just don't know .NET well enough yet, but I have yet to
Maybe I should back-up and widen the scope before diving into the title question...

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.