Differences Between jQuery bind() vs live() vs delegate() vs on() Methods

Posted By : Bipul Kumar Tiwari

.bind() , .live() , .delegate() and .on() all these 4 are jquery methods and all are used for attaching events to selectors (elements). In this post, I will explain you how these functions are different from each other.

.bind():

This is the easiest and quick method to bind events. But the issue with bind() is that The bind() method will not attach events to those elements which are added after DOM is loaded. In simple word .bind() doesn't works for dynamically added elements or future elements.

Bind method

.live():

This method overcomes the disadvantage of bind(). The live() method will attach events to those elements which are added after DOM is loaded. In simple word live() works for dynamically added elements or future elements.

Live method

Note:

The live() method will not work in chaining . live function needs to be used directly on a selector/element .below code will not work using live() method.
Live not working method

.delegate():

This method overcomes the disadvantage of live(). using delegate() method we can work in chaining.

Syntax:

        $(selector).delegate(childSelector,event,data,function)
Bind Delegate

.on() :

on() method is also a jquery method and it is used to overcome the live() method because live() was depreciated with jquery version 1.7 so the new method was introduced names as on() method. This method provides all the goodness of all the previous methods (above 3 methods) and it makes uniformity for attaching event handlers (selected elements and child elemnets).
It's basically the replacement of bind() live() and delegate() method. And it also work on current as well as future elements.

Syntax:

        $(selector).on(event,childSelector,data,function,map)
Bind on


Related Articles

 

About the Author

author
Its me BIPUL who is logically minded creative at heart , a good communicator , a self taught full stack developer. I constantly focuses on my thinking , reading , collecting and creating my work in a order to enhance my skills.

I discover new dimensions for growing bussiness with a proven record in creating database and programming. I have a strong technical skills as well as strong interpersonal skills. Read more...
 

Browse By Category

Popular Articles