Reputation: 25928
How can I access my JQuery UI Widgets options
property? For example, how do I access the option name
from the outside?
$.widget( "my.myWidget", {
options: {
name: "foo"
},
});
The following doesn't work, also see JSFiddle:
$(document).ready(function() {
var w = $('<p>abc</p>')
.appendTo('body')
.myWidget({name: "bar"});
// How do I access the option/property 'name'?
alert("Name=" + w.name);
alert("Name=" + w.options.name);
alert("Name=" + w.myWidget('name'));
});
Upvotes: 1
Views: 154
Reputation: 1212
I have works a bit with the widget options and i see that you need to implement each methods for your new widget.
i have rewrite it in this way:
(function ($) {
$.widget( "my.myWidget", {
options: {
name: "foo"
},
value(){
return this.options;
},
});
})(jQuery);
$(document).ready(function() {
var w = $('p').myWidget({name: "bar"});
alert("Name=" + w.myWidget("value").name);
});
where with myWidget("value")
value is the name of the function declared in your widget.
Upvotes: 1