Post #32112
April 03, 2015, 01:01:17 PM
Being someone who codes jQuery on a fairly regular basis (seriously, I love it!) and having not seen any instances where you would code using the second code block you provide, Wintermoot, I'm not entirely sure where you got the idea that you could code using that shorthand.
I believe the reason you use anonymous functions is that you are passing the function as an argument to the ready function. That means you can have multiple instances of code all calling the ready function with their own anonymous blocks of code they want to execute, and when the website fully loads, they will all execute one after another.
However, if you want a shorthand version, you can use this:
$(function(){
// jQuery methods go here...
});
Oh, and the way I would see you code the ready function is to have it appear in one place where you can put all of the code you want executed when things are ready (usually in the footer that gets put on every page).