Ready jquery document handler

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?

+5
source share
2 answers

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

+9
source

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, , .

+3

All Articles