What’s the difference between jQuery .live() and .on()

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.

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()!

Leave a Comment