4

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.

2 Answers 2

6

You can. The syntax (I believe) is as follows:

$('#some-element').MyWidget("public_method_with_params", word);
1
  • No luck :( Currently i have used $('#some-element').data("MyWidget"). public_method_with_params(word);
    – Prasanna
    Mar 14, 2012 at 8:09
1

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.