views:

55

answers:

1

I am loading an external page that relies heavily on jquery into a div with the $.ajax(); method.

The obvious problem is that the new content needs to be binded to the dom for jquery to work... Everyone talks about just using $.getScript to do this but I can't get it to work. Can some one give me an example and not just a link to the jquery doc page for $.getScript ?

This external page has 6 js files included in it and I need them all binded to the new content as a whole and not per div as in all of the examples I can find.

+1  A: 

"new content needs to be binded to the dom for jquery to work"

I assume that you mean that the events binded on elements do not work for the dynamically loaded content. If this is the case, you must bind the elements with live() method. So instead of:

$('#element').click(function() { ... });

Do:

$('#element').live('click', function() { ... });

This way your binds will also affect the loaded content.

If you understood your problem wrong, please let me know.

Tatu Ulmanen
Right... this works with binding one event to an element... but what do you do if you have several functions defined in another js file that you want to bind to new content?
websiteguru
How are these 'several functions' you mentioned bound to the 'old' content?
Tatu Ulmanen
Im loading an external form into a div. So the js in the external form has a bunch of validation scripts ie "onclick", "keyup", "hover",checks passwords match and strength etc...
websiteguru
Then bind those onclick, keyup and hover events with `live` and they will work on the loaded content. There should be no need to do otherwise, if that doesn't work for you, you might want to reconsider your code's structure.
Tatu Ulmanen
I already stated that this is the issue I am trying to avoid. The question is if it is possible to simply add external javascript functions to content loaded after the dom is ready without adding live to each function. A sort of blanket live statement.
websiteguru