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()!
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()!
I am the author of a Chrome extension "Comment Save" which uses jQuery, and one which used .live(). The way the extension works is by attaching a listener to all the textareas using .live() - this worked well since whenever the document changed it would still attach the listener to all the new textareas.
I moved to .on() but it doesn't work as well. It doesn't attach the listener whenever the document changes - so I have reverted back to using .live(). That is a bug I guess in .on(). Just be careful about it I guess.
One difference that people stumble on when moving from .live() to .on() is that the parameters for .on() are slightly different when binding events to elements added dynamically to the DOM.
Here's an example of the syntax we used to use with the .live() method:
$('button').live('click', doSomething);
function doSomething() {
// do something
}
Now with .live() being deprecated in jQuery version 1.7 and removed in version 1.9, you should use the .on() method. Here's an equivalent example using the .on() method:
$(document).on('click', 'button', doSomething);
function doSomething() {
// do something
}
Please note that we're calling .on() against the document rather than the button itself. We specify the selector for the element whose events we're listening to in the second parameter.
In the example above, I'm calling .on() on the document, however you'll get better performance if you use an element closer to your selector. Any ancestor element will work so long as it exists on the page before you call .on().
Now important thing...my solution only works if I use .live instead .on. If I use .on then the event gets fired after form gets submitted and which is too late. Many times my forms gets submitted using javascript call (document.form.submit)
So there is a key difference between .live and .on . If you use .live your events get fired immediately but if you switch to .on it doesn't get fired on time
.live() method is used when you deal with the dynamic generation of contents... like I have created on program that adds a tab when i change the value of a Jquery Slider and I want to attach the close button functionality to every tabs which will generated... the code i have tried is..
var tabs = $('#tabs').tabs();
// live() methos attaches an event handler for all
//elements which matches the curren selector
$( "#tabs span.ui-icon-close" ).live( "click", function() {
// fetches the panelId attribute aria-control which is like tab1 or vice versa
var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
$( "#" + panelId ).remove();
tabs.tabs( "refresh" );
});