Possible Duplicate:
what is difference of $(function(){ }); and $(document).ready(function() { }) ;?
What are the differences between $(document).ready(function(){}) vs $(function(){})
and should I write it in the $ form or the new jQuery(document).ready(function(){ }) way?
If I have google api loaded is google.setOnLoadCallback(function() { a better way? or is it the same thing?
I’ve also seen people use $(function($){})
Can somebody help me, I’m lost. I bugs me when I don’t know the code I write. I guess I should read through the library. Are the all being defined as the same thing?
The two ways are equivalent, I personally prefer the second,
$(function() {});it’s just a shortcut for document ready.About the
new jQuery(document)...construct, you don’t really need to use thenewoperator, jQuery will use it internally if you don’t.The argument that the
readyhandler function receives, is the jQuery object itself.That’s quite useful where you have to run jQuery in compatibility mode with other libraries, for example:
The
$argument inside the callback will refer to the jQuery object, outside that function it might refer to another library like PrototypeJS.