In jQuery v1.7 a new method, on was added. From the documentation:
‘The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers.’
What’s the difference with live and bind?
on()is an attempt to merge most of jQuery’s event binding functions into one. This has the added bonus of tidying up the inefficiencies withlivevsdelegate. In future versions of jQuery, these methods will be removed and onlyonandonewill be left.Examples:
Internally, jQuery maps all these methods and shorthand event handler setters to the
on()method, further indicating that you should ignore these methods from now on and just useon:See https://github.com/jquery/jquery/blob/1.7/src/event.js#L965.