Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Jquery.live() vs jquery.delegate()
1. Difference between jQuery live() and delegate()
S.No jQuery.live() jQuery.delegate()
1 Whether it can be used with Whether it can be used with
chaining or not ? chaining or not ?
live() cannot be used with delegate() can be used with
chaining .So, the below thing chaining as provided below,
cannot be done,
$
$ (‘#foo’).children(‘table’).delegate(‘tr’
(‘#foo’).children(‘table’).find(‘td’ , ‘click’, function(){
).live(‘click’, function(){ blah blah...
blah blah... });
});
2 Performance: Performance:
Live() default context is In delegate we can set context
document…. so it bubble till which cause less traverse
document which cause the
performance issue. $(‘#mytable’).delegate(‘a’,‘click’,
function(){
But, in jQuery 1.4 , option is blah blah...
provided to define context for });
live other than document as
given below,
$(‘a’, $(‘#mytable’)
[0]).live(‘click’, function(){
blah blah...
});
Note: Context is defining the
search limit to bubble to top
level of element.
Summary:
1. Both live() and delegate() are used to attach event to current element and future
elements which we append after DOM loaded e.g. we load some table rows using
ajax.
2. By considering performance factor,so it is better to use delegate all the time instead
of live() and bind().
Reference:
http://www.trickyclicks.com/web-coding/javascript/difference-between-jquery-live-and-
delegate.html
2. And, further updates on difference between questions and answers, please visit my
blog @ http://onlydifferencefaqs.blogspot.in/