I see there's a new method .on() in jQuery 1.7 that replaces the .live() in earlier versions.
.on()
.live()
I'm interested to know the difference between them and what the benefits are of using this new method.
It's pretty clear in the docs why you wouldn't want to use live. Also as mentioned by Felix, .on is a more streamline way of attaching events.
.on
Use of the .live() method is no longer recommended since later versions of jQuery offer better methods that do not have its drawbacks. In particular, the following issues arise with the use of .live(): jQuery attempts to retrieve the elements specified by the selector before calling the .live() method, which may be time-consuming on large documents. Chaining methods is not supported. For example, $("a").find(".offsite, .external").live( ... ); is not valid and does not work as expected. Since all .live() events are attached at the document element, events take the longest and slowest possible path before they are handled. Calling event.stopPropagation() in the event handler is ineffective in stopping event handlers attached lower in the document; the event has already propagated to document. The .live() method interacts with other event methods in ways that can be surprising, e.g., $(document).unbind("click") removes all click handlers attached by any call to .live()!
Use of the .live() method is no longer recommended since later versions of jQuery offer better methods that do not have its drawbacks. In particular, the following issues arise with the use of .live():
$("a").find(".offsite, .external").live( ... );
document
event.stopPropagation()
$(document).unbind("click")
2.1m questions
2.1m answers
60 comments
57.0k users