Possible Duplicate:
Performance difference between jQuery's .live('click', fn) and .click(fn)
Does jQuery live() / delegate() affect significantly performance?
$('a').live('click', ...
$('a').click(... <== is this faster? and how much?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer is that it depends:
clickwill be faster for few elements. You’ll have one bound function for each element, but no overhead for other clicks.delegateis faster for many elements. There’s only one event handler being bound, even for hundreds of elements. The overhead of checking missed clicks is miniscule compared to binding one function for each element.delegateis always faster thanlive. It can limit where in the page it will listen for events, and does not need to iterate over all the elements when binding.If you’re after hard numbers, I read in an article about delegate that the tipping point is around 3-5 elements. Use
clickfor less than that, anddelegatefor more. I can’t back that up with a link unfortunately, but that’s the general rule I’ve been following.