I have something similar to this:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>JQuery Test</title>
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/page.js"></script>
</head>
<开发者_开发百科body>
<div id="searchResults" ></div>
</body>
</html>
The searchResults div will get populated by a jQuery .load(). The result that is returned into the div has javascript to be executed. This much works fine.
Now I need some of the javascript that gets returned into searchResults to call a function in page.js. This currently does not work. Is this possible?
UPDATE:
I sort of found the problem. In page.js the function I am trying to call is inside a $(document).ready statement. If declare the function outside of the document ready it works. Anyone care to explain to me why this is and is there a way to leave it in the document ready area?
Anyone care to explain to me why this is and is there a way to leave it in the document ready area?
It is not is the same scope as the other function. You know what I mean? It is hidden because it is inside another function (the document ready function). It is the same with a variable. If you declare a local variable inside a function, some code outside the function can't just directly reference that variable that is inside another function.
When you load into $('#searchResults')
the document.ready()
was already called so anything wrapped in those tags will not be done.
精彩评论