I have a webpage with jQuery (it seems that version does not matter) on Chrome. The page is fully loaded. I'm writing this in the Chrome console:
$(document).on('ready', () => {console.log('Hello');});
I get no 'Hello' in the console. However when writing this:
$(document).ready(() => {console.log('Hello');});
'Hello' is in the console now.
There is nothing special about that in the documentation, so why it is working in such a way? I've always thought that the on()
function is just a syntax sugar.
on()
function does not introduce any new functionality that did not already exist, it is just an attempt to standardize event handling in jQueryready
is not an event - it's$(document).ready()
. It's like asking why you can't do$(document).on("fadeIn"...
click()
andon('click')
, there isn't one. All shortcut methods callon()
internally.