what is difference between
$(function(){
});
and
$(document).ready(function() {
});
The two are exactly equivalent: use whichever form you like.
That said, I personally always use the expanded form $(document).ready(function(){});
for the simple reason that it is completely obvious what the code is doing. The approximate idea is that of "self-documenting code". Anyone coming to the code later on will immediately see that the code is to be run on the document
's ready
event. With the short-hand form, you have to rely upon the reader of your code understanding the meaning.