I'm developing a custom jquery plugin with callback functionality. I have assigned plugin to 2 different element like
$("#id01").plug({
onsave: function(res) { console.log(res); }
});
$("#id02").plug({
onsave: function(res) { console.log(res); }
});
if i make any changes in element 1 and click save, callback function onsave() will trigger on both the elements. Please help me to resolve this.
Here is the sample code:
(function($){
$.fn.plug = function(options) {
var param = $.extend({
selector: this.selector,
onsave: function() {}
}, options);
$(".savebtn").live('click', function() {
if(typeof param.onsave == 'function') {
var data = value;
param.onsave.call(this, data);
}
});
}
}(jQuery));
live()is so deprecated. Useon()instead. api.jquery.com/on