I donβt know why it is important to define a function in the ready() scope, but you can make it work by declaring foo in front:
<html><head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> <script> var foo; </script></head><body> <input type="button" onclick="foo()" value="Click me"> </body></html>
Obviously, you cannot call foo() from the built-in script right after ready() , because the ready() code is not already running, but you can call the function later.
Just make sure nothing can try calling foo() before running ready() code (or making the initial declaration of foo() harmless function).
RichieHindle Jun 28 '09 at 21:15 2009-06-28 21:15
source share