Hi guys

Thanks for the great feedback. MorningZ was right on the money with my
scenario. I'm incorporating a js file of a photo gallery which was
built by some else and all the code is wrapped in the $(document).ready
() function.

So it looks like you all seem to agree that all the methods inside
this function are not available globally so I'm going to have to re-
factor the code in the js file. I'm not to sure why the developer
wrapped it all in the ready() function but I'll have to painfully pull
it apart now... nothing's ever easy is it :)

Cheers
Matthew

On Sep 22, 10:09 am, Mike McNally <emmecin...@gmail.com> wrote:
> Well "Action1" is a local function to that jQuery "ready" function, so
> it's *never* going to be available as a global function.
>
> A couple of options:
>
> 1) Turn your wannabe-global functions into jQuery plugins
>
> 2) Explicitly add your functions to the window object
>       window['Action1'] = function() { ... };
>
> 3) Bind your functions as event handlers on the "body" object (or whatever)
>       $('body').bind('Action1', function() { ... });
>
>       ....
>
>       <body>
>         <div> <!-- whatever -->
>             <script> $('body').trigger('Action1'); </script>
>
>
>
> On Mon, Sep 21, 2009 at 7:03 PM, MorningZ <morni...@gmail.com> wrote:
>
> > Do you have like this:
>
> > External js file "code.js":
>
> > $(document).ready(function() {
> >       function Action1() {
> >          // do stuff
> >       }
> > });
>
> > Html file "index.htm":
>
> > <html>
> >    <head>
> >       <script type="text/javascript" src="code.js"></script>
> >    </head>
> >    <body>
> >         ... some html here ...
> >         <script>Action1()</script>
> >         ... some html here ...
> >    </body>
> > </html>
>
> > if so, then "Action1" isn't defined yet (and it won't be until *all*
> > the HTML is spit out to the browser) and not available to use.....
>
> > see this quick example:
>
> >http://jsbin.com/edovi/edit
>
> > the alert of "Run Action1" happens *before* the document is ready, and
> > as a result, the event getting wired up
>
> > On Sep 21, 7:11 pm, Matthew <matthewbchamb...@gmail.com> wrote:
> >> Hi all
>
> >> I've got a js file where all the functions are wrapped inside $
> >> (document).ready(). I want to call one of the function from within the
> >> HTML but it says that the function "is not defined". Any ideas?
>
> >> Cheers
> >> Matthew
>
> --
> Turtle, turtle, on the ground,
> Pink and shiny, turn around.

Reply via email to