Whenever I read about event registration in jQuery they all say that we should try to add event handlers to the nearest parent, and avoid adding event listeners to the document, because according to resources they are slow and not efficient.
But why they are slow? Apparently it's because the event will have to bubble up to the document, which will take time. Then it will be compared to a list of selectors to call, e.g.
$(document).on("click", ".abc", function(){ })
$(document).on("click", ".abc2", function(){ })
So here if I click an element, the click event will be bubble up to the document and then it will match the selector list (".abc, .abc2")...and that is inefficient. OK I got it but what if I have only have one selector in the list ? e.g.
$(document).on("click", "*", function(){ })
Will it be slow too ? If so why?
Basically i'm trying to create a google's jsaction similer lib, so I will write like this:-
$(document).on("click", "[jsaction]", function(){ })
Because this will be the only selector, so i don't think it will be slow ? or will it be ?
and if attaching event to document is not efficient, then what about a completely ajax application? my application is completely ajax, and every page will be downloaded by ajax. Is there another, more efficient solution?