Is there any difference between using:
$(document).ready(function(){
against.
$(function(){
Does one of them work better than the other, or is the first only a short version of the first?
The latter is a short version of the finished handler.
:
$(function(){ })
- short version:
$(document).ready(function(){ }
Both perform the same task.
jQuery knows its slogan very well:
'Code less do more
From docs :
All three of the following syntaxes are equivalent:* $(document).ready(handler) * $().ready(handler) (this is not recommended) * $(handler) $(document).bind( "", ). : , .bind( "ready" ) ..ready() jQuery, , .
All three of the following syntaxes are equivalent:
* $(document).ready(handler) * $().ready(handler) (this is not recommended) * $(handler)
$(document).bind( "", ). : , .bind( "ready" ) .
.ready() jQuery, , .