Response title
This is preview!
And specifically delegate() or the proper on() methods are more efficient then live()Did you know that the jQuery.bind()
,.live()
, and.delegate()
methods are just one line pass throughs to the new jQuery 1.7.on()
method? The same is true of the.unbind()
,.die()
, and.undelegate()
methods.
matchesSelector
method to determine which event handler to invoke, if any.The graph on that page you link is pretty accurate.With that in mind, jQuery 1.7 event handling was refactored with an eye to making delegated events much faster, especially for the most common cases.To optimize the code for the most commonly used forms of selectors, we examined a cross-section of code from Google Codesearch. Nearly two-thirds of the selectors used in
.live()
and.delegate()
method calls were in the formtag#id.class
where one or more of tag, id, or class were used. By parsing those simple selectors in JavaScript at the time the event was attached, we were able to outperform even the browser’s native-code implementations ofmatchesSelector
during event delivery. For more complex selectors we still use the Sizzle engine, so all existing code should continue to work.
Mea culpa for getting it backwards.I don't understand how you (as a group, not any individual) are coming to the conclusion that .delegate or .live is more or less efficient than using .on in the same way.
© 2013 jQuery Foundation
Sponsored by and others.