Jquery: Calling functions from different documents

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-04-17T01:33:18Z Indexed on 2010/04/17 1:43 UTC
Read the original article Hit count: 246

Filed under:
|
|

Hi,

I've got some Jquery functions that I keep in a "custom.js" file. On some pages, I need to pass PHP variables to the Jquery so some Jquery bits need to remain in the HTML documents. However, as I'm now trying to refactor things to the minimum, I'm tripping over the following:

If I put this in my custom.js:

$(document).ready(function()
{
   function sayHello() {
      alert("hello");
   }
}

And this in a HTML document:

<script type="text/javascript">
   $(document).ready(function()
   {
      sayHello();
   });
</script>

... the function doesn't get called. However, if both are placed in the HTML document, the function works fine.

Is there some kind of public property I need to declare for the function or how do I get Jquery functions in my HTML to talk to external .js files? They're correctly included and work fine otherwise.

Thanks.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about function