Fuxi
Fuxi

Reputation: 7599

jQuery: applying plugin using a string

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?

Upvotes: 1

Views: 36

Answers (1)

Amadan
Amadan

Reputation: 198324

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)

Upvotes: 4

Related Questions