• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

JavaScript not working with jQuery .load() dynamic content

I am making a site that calls data in from another location using the jQuery .load() event. However, the content that has been brought in cannot interact with the JavaScript currently on the page.

In the below page, I have programmed it to to load content based on the anchor link that is clicked or what is loaded in from the address bar in a browser.

This works fine for all the static links on the page but NOT the links that have been loaded dynamically.

Is there a way to get my code to see the links in the dynamic data that has been imported?


Called in from


(view source to see code)

Also, is there a way to load both the HTML and JavaScript into a DIV using jQuery?

Many thanks,

1 Solution
Ok, I suggest you look at the "live" event http://api.jquery.com/live/

Telling jQuery to do something live means it will do it to all current AND FUTURE elements, which should overcome your issues with jQuery not seeing the new elements in the DOM.

Alternativelty, if you know what you are going to be loading into the page and what you'll want to interract with, you can be more specific and use the "bind" function of jQuery to bind functions to the newly added elements.

As for your second question, I'm not sure how you would do that, and I'm also not sure if it's a good idea.
INeedHelpAuthor Commented:
Thanks that works a treat.

The odd thing is I had already tried this, I must have done something wrong somewhere. Your comment gave me confidence that I was on the right track, so now I've gone back and done it again properly and it's working great :o)

Thanks again

Michel PlungjanIT ExpertCommented:
Please note the .live event handler has been superseded by the .on event handler
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now