$(document).ready shorthand

Mark Brown picture Mark Brown · May 14, 2011 · Viewed 163.4k times · Source

Is the following shorthand for $(document).ready?

(function($){

//some code

})(jQuery);

I see this pattern used a lot, but I'm unable to find any reference to it. If it is shorthand for $(document).ready(), is there any particular reason it might not work? In my tests it seems to always fire before the ready event.

Answer

Kyle Trauberman picture Kyle Trauberman · May 14, 2011

The shorthand is:

$(function() {
    // Code here
});