What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})

The difference is, as the docs say

There is also $(document).on( “ready”, handler ), deprecated as of jQuery 1.8. This behaves similarly to the ready method but if the ready event has already fired and you try to .on( “ready” ) the bound handler will not be executed. Ready handlers bound this way are executed after any bound by the other three methods above. [em mine]

.bind and .on behave similarly.


This is the only difference between

$( document ).ready( handler )
$().ready( handler ) // (this is not recommended)
$( handler )

and

$( document ).on( "ready", handler )
$( document ).bind( "ready", handler )

that’s mentioned in the docs, so I’m guessing is the most likely source of your issue

Leave a Comment