The following question is inspired by this blog entry at ajaxian.com and this comment by paul irish.
Here is a way to declare live event.
$("li a").live(...)
As per this blog entry, it is my understanding that live events are nothing but a catch all at the document level. Any event that bubbles all the way to the top are caught by live events and if the selector is matching then the function is invoked.
It is my understanding that on document ready if I invoke
$("li a").live('click', ..)
then all jQuery should do is to put the literal selector 'li a' in memory somewhere. Now when a click happens and if that click bubbles all the way to the top then live should check what is the target element. If the target element satisfies the rule of 'li a' then the function should be fired otherwise ignored this bubbled up event.
Based on that presumption on document ready when I am calling
$("li a").live('click', ..)
then ideally jQuery should not actually go looking for all the element matching 'li a' because jquery does not do anything with those elements. I know for sure that the elements that are currently present in the document matching 'li a' are not bound to any event handler.
If all jQuery has to do is to put the literal 'li a' at the document root level then why go looking for elements matching the criteria 'li a' on document ready. But based on the comment link that I mentioned at the top, it seems jQuery actually goes about looking for element on document ready.
My question is why should live method find all the 'li a' methods when it is not going to do anything with them. I guess the live syntax should have been something like
$.live('li a', 'click', function(){})
Am I missing something here?