tags:

views:

117

answers:

2

i want to know main difference between

 .live()

and

.bind() method of jquery

+8  A: 

The main difference is that live will work also for the elements that will be created after the page has been loaded (i.e. by your javascript code), while bind will only bind event handlers for currently existing items.

// BIND example
$('div').bind('mouseover', doSomething);
// this new div WILL NOT HAVE mouseover event handler registered
$('<div/>').appendTo('div:last');

// LIVE example
$('div').live('mouseover', doSomething);
// this new appended div WILL HAVE mouseover event handler registered
$('<div/>').appendTo('div:last');
RaYell
thanks for the infomation
Pranay Rana
+4  A: 

you should consider to use .delegate() instead of .live() whereever possible. Since event delegation for .live() always targets the body/document and you're able to limit "bubbling" with .delegate().

see api.jquery.com

Kind Regards

--Andy

jAndy
thanks for the infomation
Pranay Rana