Why the expression for live needs to be evaluated in jQuery

The following question is inspired by [this blog entry][1] at ajaxian.com and [this comment by paul irish][2]. Here is a way to declare live event. $("li a").live(...) As per [this blog entry][3], 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? [1]: http://ajaxian.com/archives/jquery-bondage [2]: http://ajaxian.com/archives/jquery-bondage#comment-276284 [3]: http://www.neeraj.name/blog/articles/882-how-live-method-works-in-jquery-why-it-does-not-work-in-some-cases-when-to-use-livequery

以上就是Why the expression for live needs to be evaluated in jQuery的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏