This is a simple widget mock:
(function ($) {
$.widget("ui.myDummyWidget", {
options: {
},
_create: function () {
},
hide: function () {
this.element.hide();
},
_setOption: function (key, value) {
$.Widget.prototype._setOption.apply(this, arguments);
},
destroy: function () {
$.Widget.prototype.destroy.call(this);
}
});
} (jQuery));
It only adds a method hide that you can call to hide the element. Easy if done from within widget
this.hide();
But a common scenario is that you want to call methods on a widget instance from the outside (Ajax update, or other external events)
So what is the best way of accessing the widget instance? One way is to add the reference to the widget to the element, ugly...
_create: function () {
this.element[0].widget = this;
},
Then you can access it from the outside doing
this.dummy = $("#dummy").myDummyWidget();
this.dummy[0].widget.hide();