You can use datato associate your object with the DOM element to which it belongs:
$.fn.pluginName = function(opts) {
if(typeof(opts) == "string"){
this.each(function(){
var obj = $(this).data('ClassName');
if(obj){
if(opts == "show") obj.myShowMethod();
else if (opts == "hide") obj.myHideMethod();
}
})
} else {
var conf = $.extend({},opts);
this.each(function() {
var obj = new ClassName(conf,$(this));
$(this).data('ClassName', obj);
});
}
return this;
}
Also check out Starter for jQuery , which uses a template datato bind an object to a DOM element.
source
share