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);
Sign up to request clarification or add additional context in comments.

1 Comment

No luck :( Currently i have used $('#some-element').data("MyWidget"). public_method_with_params(word);
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()

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.