Explain .bind() vs .live() vs .delegate() vs .on()

Answers were Sorted based on User's Feedback



Explain .bind() vs .live() vs .delegate() vs .on()..

Answer / chaitanya

All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other.

.bind(): This is the easiest and quick method to bind events. But the issue with bind() is that it doesn't work for elements added dynamically that matches the same selector. bind() only attach events to the current elements not future element. Above that it also has performance issues when dealing with a large selection.

.live(): This method overcomes the disadvantage of bind(). It works for dynamically added elements or future elements. Because of its poor performance on large pages, this method is deprecated as of jQuery 1.7 and you should stop using it. Chaining is not properly supported using this method.

.delegate(): The .delegate() method behaves in a similar fashion to the .live() method, but instead of attaching the selector/event information to the document, you can choose where it is anchored and it also supports chaining.

.on(): Since live was deprecated with 1.7, so new method was introduced named ".on()". This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers.

Find out more here

Is This Answer Correct ?    1 Yes 0 No

Explain .bind() vs .live() vs .delegate() vs .on()..

Answer / sourav basak

Thanks for sharing this article that distinguishes jQuery .bind() vs .live() vs .delegate() vs .on(). And it clears in depth view before applying to bind event to the elements.
Version comparison also supports when one method migrate to another one.

Here is another links for differentiate between .bind() vs .live() vs .delegate() vs .on().
http://www.namasteui.com/differences-between-jquery-bind-vs-live-vs-delegate-vs-on/

Hope this helps too. Thanks a lot.

--
Regards,
Sourav Basak [Blogger, Entrepreneur, Thinker]
Namaste UI

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More jQuery Interview Questions

How do you attach a event to element which should be executed only once?

1 Answers  


What is the struts2 jquery plugin and its advantages.

0 Answers  


Can you use any other name in place of $ (dollar sign) in jQuery?

0 Answers  


How can events be prevented from stopping to work after an ajax request?

0 Answers  


Explain the difference between event.preventdefault and "return false"? : jquery mobile

0 Answers  






What are the types of selectors in jQuery?

0 Answers  


Explain the animate function.

0 Answers  


Why jQuery is needed?

0 Answers  


what is the use of param() method in jquery .

0 Answers  


What is the use of delay() method in JQuery?

0 Answers  


Change the url for a hyperlink using jquery?

0 Answers  


What is cdn and how jquery is related to it?

0 Answers  


Categories