Just put the calls to the functions that do the work inside of .ready().
Put everything else outside of it.

As for anonymous functions, they are good for creating a context that avoids
polluting your name space.  When the function ends, everything defined
within disappears into oblivion unless there is some reference to it from
the outside.  So, you need to create variables or objects outside, if you
want to be able to keep them around.  Or, you need to bind the things that
are inside the closure to events on objects (such as the DOM) that are
outside.



On Fri, Dec 11, 2009 at 2:02 PM, Jojje <jojjsus_chr...@hotmail.com> wrote:

> My question is about syntax, or how to wite jquery code.
> Is the example below ok? Putting all your code between document.ready
> all your code with anonymous functions?
>
> $(document).ready(function() {
>   $('a.link1').click(function() {
>      //code
>   });
>   $('a.link2').click(function() {
>      //code
>   });
>   $('form.form1').submit(function() {
>      //code
>   });
>   $('img.myPic1').css('border','solid 3px red');
> });
>
> or should i call named functions?
>
> $(document).ready(function() {
>   $('a.link1').click(clickFunction1());
>
>   $('a.link2').click(clickFunction2());
> });
>
> function clickFunction1() {
>   //code
> }
>
> function clickFunction2() {
>    //code
> }
>
> I´ve heard that anonymous functions is a faster way??
>
> thanks in advance
>
> George
>



-- 
John Arrowwood
John (at) Irie (dash) Inc (dot) com
John (at) Arrowwood Photography (dot) com
John (at) Hanlons Razor (dot) com
--
http://arrowwood.blogspot.com
Mike Ditka <http://www.brainyquote.com/quotes/authors/m/mike_ditka.html>  -
"If God had wanted man to play soccer, he wouldn't have given us arms."

Reply via email to