The jQuery API documentation states that we should use the newer on()
function instead of the older (sometimes deprecated) ways of attaching an even handler to elements.
From my understanding, the on()
requires to be bound to an element that "currently exists" in the page (DOM). In these days of building web sites where pages are mostly dynamically loaded (via Ajax) and injected, this pretty much forces us to bind it to the document element.
I have mostly used the live()
method to bind to "future elements". This worked well for me, but I can't simply replace my live()
for the newer on()
because my elements don't yet exist and if I do, nothing works.
I could simply use $(document).on()
instead but I'm scared of a huge overhead that it seems to impose on event delivery. At least from what I understand from their documentation.
Can anyone comment on the potential penalty the on()
function may bring in my particular case. And possibly, if anyone can comment on what the rational is for jQuery to constantly deprecate their event binding API's (which is not backwards compatible in this case)?