I am developing a plugin, after add object to the plugin i want to call some events to same object from outside, how can i do that
(function ($, undefined) {
jQuery.fn.pluginname = function (options) {
var set = $.extend({
opacity: 0.5
}, options);
//if(options.type)
var cdiv = this;
cdiv.css("opacity",set.opacity);
function callthis()
{
cdiv.css("display","none");
}
}
})(jQuery);
jQuery("#first").pluginname({opacity:0.5});
jQuery("#second").pluginname({opacity:0.5});
// call this function later
jQuery("#first").pluginname("callthis");
The usual way is to have your plugin accept "methods" as string arguments, e.g.:
Internally in the plugin, you route that request to the function.
Normally you'd also want to store the options used initially somewhere other than just in the closure;
data
is useful for that.And you normally have a
"destroy"
method to remove the plugin from elements.So:
Live Example | Source
Try this: