jQuery offers various event handlers like on(), live() and bind(). Though, there are some minor differences which are discussed below.
bind() method: This method only attaches events to elements which exist beforehand i.e. state of initialized document before the events are attached. If the selector condition is satisfied for an event afterward, bind() will not work on that function. It also won’t work in the case if selector condition is removed from the element.
- Example:
<!DOCTYPE html><html><head><!-- CDN for jQuery --><scriptsrc=</script></head><body><divclass="content"><pclass="a">This is Statement 1.</p><script>/* Here, the bind() works on elementsinitialized beforehand only */$(".a").bind("click",function(){$(this).css("color","red");});</script><pclass="a">This is Statement 2.</p><!-- click() method works on Statement1 but not on Statement 2. --></div></body></html>chevron_rightfilter_none - Output:
Before clicking those statement:

After clicking those statement:

live() method: This method attaches events not only to existing elements but also for the ones appended in the future as well but it won’t work in the case if selector condition is removed from the element.
Note: The live() method was deprecated in jQuery version 1.7, and removed in version 1.9.
- Example:
<!DOCTYPE html><html><head><!-- Old CDN for .live() to work in jQuery --><scriptsrc=</script></head><body><divclass="content"><pclass="a">This is Statement 1.</p><script>/* live() method works for elementsappended later as well */$(".a").live("click",function(){$(this).css("color","red");});</script><pclass="a">This is Statement 2.</p><!-- live() method works on both Statement1 and Statement 2. --></div></body></html>chevron_rightfilter_none - Output:
Before clicking those statement:

After clicking those statement:

on() method: This method attaches events not only to existing elements but also for the ones appended in the future as well. The difference here between on() and live() function is that on() method is still supported and uses a different syntax pattern, unlike the above two methods.
- Example:
<!DOCTYPE html><html><head><!-- CDN for jQuery --><scriptsrc=</script></head><body><divclass="content"><pclass="a">This is Statement 1.</p><script>/* Works on all elements within scopeof the document */$(document).on("click",".a",function(){$(this).css("color","red");});</script><pclass="a">This is Statement 2.</p><!-- on() method works on both Statement1 and Statement 2. --></div></body></html>chevron_rightfilter_none - Output:
Before clicking those statement:

After clicking those statement:

Differences summarized for the above methods:
| Property | bind() | live() | on() |
| Deprecated | Yes | Yes | No |
| Removed | No | Yes | No |
| Scope | Elements initialized beforehand | For both current and future event binding | For both current and future event binding |
| Syntax: | $([selector]).bind([event],[function]); | $([selector]).live([event],[function]); | $(document).bind([event],[selector],[function]); |
Recommended Posts:
- jQuery | bind() with Examples
- jQuery | live() Method
- Replace live() with on() in jQuery
- How to bind 'touchstart' and 'click' events but not respond to both ?
- AngularJS | ng-bind Directive
- AngularJS | ng-bind-html Directive
- AngularJS | ng-bind-template Directive
- AngularJS | angular.bind() Function
- bind command in Linux with Examples
- Underscore.js | _.bind() Function
- How to bind an array to an IN() condition in PHP ?
- v-bind Directive in Vue.js
- Node.js socket.bind() Method
- Lodash _.bind() Method
- How to bind 'this' keyword to resolve classical error message 'state of undefined' in React?
- Google AMP amp-bind-recaptcha
- How to calculate area of circle dynamically using amp-bind-macro in Google AMP ?
- What is Initialize state in amp-bind of Google AMP ?
- How to change/update image size dynamically using amp-bind in Google AMP ?
- How to change/update CSS class dynamically using amp-bind in Google AMP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


