I've created a plugin which I need to be able to unbind and rebind at will. How can I
package this within a method in my plugin so that it can be called at will?
My plugin is like so:
(function($) {
$.fn.myPlugin = function(options) {
.................
.................
.................
.................
.................
.................
};
})( jQuery );
And called like...
$('#selector').myPlugin();
Edit: Basically, I want to add a destroy method to my plugin
Well somthing like that:
delete $.fn.MyPlugin;
Optionally you can write destroy method into your plugin e.g.:
destroy: function() {
this._destroy(); //or this.delete; depends on jQuery version
this.element.unbind( this.eventNamespace )
this.bindings.unbind( this.eventNamespace );
//this.hoverable.removeClass( "hover state" );
//this.focusable.removeClass( "focus state" );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With