Replace live method to on in Jquery

I have been using the live method from jquery to attach the future element for some trigger event. But after jquery 1.7, they just annouce the live method is deprecated.

Instead we can use the “on” function to replace the “live”.

Old “live” function

$('.js-click').live('click', function() {

    alert("click event attach by live ");

});

New method “on”

The first one, it will only work for element that’s exist in page load. Future element will not work for this case.

$('.js-click').on('click', function() {

    alert("click event attache on ");

});

The Second one, we can link the future element by using this.

$(document).on('click', '.js-click', function() {

    alert("click by on method for future element");

});

Related Articles:
http://stackoverflow.com/questions/8752321/jquery-live-vs-on-method-for-adding-a-click-event-after-loading-dynamic-ht
http://www.elijahmanor.com/differences-between-jquery-bind-vs-live-vs-delegate-vs-on/

Source :
http://api.jquery.com/live/
http://api.jquery.com/on/

Happy Coding ! :)