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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you give me a brief history of your programming days? Where did it all start?

669


How to give face effect in jquery?

536


How to load a page using jquery mobile? : jquery mobile

545


What is the use of val() method in jquery?

596


How did you become the creator of jquery ui? Whats the story behind that?

839






How to delete cookies in jquery?

547


Differentiate between calling stop (true, true) and finish method?

576


Is Uncaught TypeError: $(…).modal not a function jquery?

549


How does jquery mobile theming work? : jquery mobile

493


Why jquery?

585


Can you please explain the difference between body onload() and document.ready() function? : jquery mobile

495


Do you know what is the use of jquery.data()?

532


Differentiate the concepts of .js and .min.js?

540


How to get the current offset of the first matched element, in pixels, relative to the document using ?

537


How to always reference latest version of jquery?

544