Reputation: 11544
I am currently using jQuery UI widget factories and i am kind of struck in calling public methods with parameter.
This is what i have done.
//Widget
$.widget('ui.MyWidget',{
public_method_without_params: function(){
//do something;
}
public_method_with_params: function(word){
//do something;
}
});
I'm trying to call public_method from outside. If it doesn't have a parameter i would have done either
(i) $('#some-element').MyWidget("public_method_without_params")
(or)
(ii) $('#some-element').data("MyWidget").public_method_without_params();
Is it possible to call the public_method_with_params similar to (i) mentioned above?
Thanks.
Upvotes: 4
Views: 4116
Reputation: 11544
Currently i have done this:
$('#some-element').data("MyWidget"). public_method_with_params(word);
and it works. Only problem is that i need to initialise "MyWidget" before this.
$('#some-element').MyWidget()
Upvotes: 1
Reputation: 1906
You can. The syntax (I believe) is as follows:
$('#some-element').MyWidget("public_method_with_params", word);
Upvotes: 6