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.
So, I have to remember that I can’t use
$(window).load(handler), I have to use
$(window).on("load", handler) instead; but on the other hand, for the
ready event it’s the other way round: I can’t use
$(document).on("ready", handler), I should use
$(handler) instead. And also,
$(handler) is the same as
$(document).ready(handler) but it is not the same as
$(document).on("ready", handler). Unlike every other event, where
$(something).on("event", handler) is the same as
That’s a lot of gratuitous inconsistencies and a lot of unnecessary things to know that one can easily miss.
$(document).on("ready", handler) should not be deprecated, and it should behave the same as
$(handler), both in whether it is fired or not and in the order of execution.
I know, you’ll tell me that it is not gratuitous and unnecessary, that it is because of how stuff is implementated. However, implementation difficulties should dealt with by implementors, not exposed to the API users.