live() & delegate() are two unique functions of jQuery. These two function look & act much like bind() function of jQuery. However they have a very different purpose.
We know that bind() function is used to binds Event Handlers to the elements matching the selector & already present in the DOM.
Lets say we have a button in the DOM with following markup.
<button id="btnSubmit" value="Submit" type="button">Click Me</button>
To attach Click Event Handler to the button, we use bind() function of JQuery as shown in the following snippet.
$('#btnSubmit').bind('click', function() {
alert('User clicked on "Click Me"');
});
bind() function is pretty good if the element for which it is used is already present in the DOM. But, if the elements are added to the DOM on the go & we want that all the elements should have a Event Handler attached with them, then I won’t consider bind() function as the best option to attach Event Handlers. If we use bind() function in such scenario, then whenever a new element is added to the DOM, after each insertion we will have to call bind() function to attach a Event Handler to the newly added element. So to avoid this JQuery’s live() or delegate() functions can be used.
live() & delegate() functions provide similar event delegation functionality. They may sometimes seem as interchangable functions but at low level they are not. live() has several serious disadvantages & is suggested to be used.
[Event Delegation Functionality: Event delegation works by binding to an element in the page, waiting for a DOM event to bubble to this element.]
HOW LIVE & DELEGATE WORKS:
Following is the code snippet of two jQuery functions live() & delegate() performing the same operation.
$('#container').delegate('button','click', function() {...});
$('#container button').live('click', function() {...});
The main difference between the two functions is, live() binds to the document & delegate() binds to the element on which its called on.
live() method provides a means to attach delegated event handlers to the document element of a page. So every time the event is triggered, it bubbles up in the tree to the document. This may be very time-consuming for large documents.
delegate() method instead provides a means to attach delegated event handlers to some parent element. So whenever the event is triggered, it bubbles up to the parent on which the method is called instead of document element.
So delegate() is a better option in terms of performance as compared to live().

