bind, live, delegate, on. What is the difference ?

All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other, Here’s a tiny bit of explanation.

.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.
– It only attach events to the current elements not future element.
– 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.
– Due to its poor performance on large pages, this method is deprecated as of jQuery 1.7.
– 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.
– It 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.

For more read here .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.