1

i wrote a jquery plugin which i'm applying like this:

div.myPlugin1();

now i want to apply it dynamically using a string:

var number = 1;
var plugin_name = "myPlugin"+number;
div[plugin_name]();

too bad this doesn't work.

Any ideas?

1 Answer 1

4
div[plugin_name].call(div);

or

div[plugin_name].apply(div);

(they differ in the way they use parameters, but behave the same for no-parameter methods)

Sign up to request clarification or add additional context in comments.

6 Comments

oops, check your answer ;-) You've doubled up.
Yeah, written the same thing twice.
Doh... meant to say apply. Thanks.
I always get confused by the first argument - is it needed? Rather, when is it needed? I understand what it's supposed to do (specify the target object of the function call).
@Madbreaks: The first argument is assigned to this inside the function.
|

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.