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

The Archive Base Latest Questions

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

Okay how can i add function to injected elements(which that element dosent exist on

  • 0

Okay how can i add function to injected elements(which that element dosent exist on first browser load). Please read through my example carefully , i hope you can understand.

For example:
i go to http://www.website.com , when it loads it loads up “functions.js” and “other.js” , inside “functions.js” there’s a code that injects a new div with ID when user click on a button.

The injection code as shown below:(functions.js –jquery)

$('a#button').click(function(){
    $('a#button').after('<div id="new">New div<br><a href="#" id="newdivlink">Another link</a></div>');
});

However there’s another on click functions loaded in another js file which is “other.js” (loaded same time as function.js load).

Inside “other.js” has the code for the onclick function when the new div’s link (#newdivlink) is clicked.

other.js :

$('a#newdivlink').click(function(){
  alert('you clicked on new div's link yay?');
});

But the problem is , the onclick function for the new div’s link(#newdivlink) cant be executed as the script can’t find the div (as it is being injected after i loads).
Or is there some problems ?

P/S if you are asking why not combine both scripts , i don’t want, as i want to try this technique out.

  • 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:45:15+00:00Added an answer on May 25, 2026 at 9:45 pm

    Try using ‘live’ instead of click:

    $('a#newdivlink').live('click', function(){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay at first I thought this would be pretty straightforward. But I can't think
Okay, I've got my normal app which is in portrait mode. I can force
Okay, I just can't get my head around multi-threading scenarios properly. Sorry for asking
Can someone show me a regex to select #OnlinePopup_AFE53E2CACBF4D8196E6360D4DDB6B70 its okay to assume #OnlinePopup
Okay people, I'm sure someone has had this issue and can help me out.
Okay, so I have a website where the user can put a search query
Okay i have two models: posts and comments. as you can think comments has
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
To anyone who can help, Thanks Okay, so I have a database holding a
This can be a good question for finding bugs. No? Okay for beginners at

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.