It's a simple scoping problem. Anything you create inside an anonymous
function will be accessible only within the function. If you need
something to be accessible between the anon. functions, simply move it
into a higher scope, like the global namespace (eh, not idea) or the
jQuery namespace (better idea).

$(function(){
    $.displayMessage(){ alert('hello world') }
});

$(function(){
    $.displayMessage();
});

On May 29, 12:18 pm, Brian FitzGerald <fitzgeraldme...@gmail.com>
wrote:
> I know that you can have more than on document ready event without
> difficulty. i.e.
>
> $(function(){
>   // document ready 1
>
> });
>
> $(function(){
>   // document ready 2
>
> });
>
> The question I have is, is there any way for them to call functions
> from one to the other?  The following does not work:
>
> $(function(){
>    function displayMessage(){ alert('hello world'); };
>
> });
>
> $(function(){
>   displayMessage();
>
> });
>
> This invokes a js error complaining that displayMessage() is not
> defined.
>
> Thanks in advance for any thoughts,
> Brian

Reply via email to