• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • 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?


http://ag-chartered-accountants.com/dynamic/what.php#it-solutions

Called in from

http://ag-chartered-accountants.com/dynamic/what-cms.php

(view source to see code)

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

Many thanks,

Mark
0
INeedHelp
Asked:
INeedHelp
1 Solution
 
chuckaliciousCommented:
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.
0
 
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

Mark
0
 
Michel PlungjanIT ExpertCommented:
Please note the .live event handler has been superseded by the .on event handler
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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