2

I have a set of jquery plugins as follows:-

fooADD(options)
fooSUB(options)
fooDIV(options)
....

I then have a plugin that acts on a with an attribute data-plugin=""

So for:-

<DIV data-plugin="fooADD">

I want to run the code:-

var item = $('<div/>').fooADD({'option':'value'});

How can I achieve this such that I can keep adding new foo plugins which can be selected from data-plugin without the need to update an array of function lookups?

1 Answer 1

4

Demo --> http://jsfiddle.net/zYfWc/

var plugin = $('div').data('plugin');
var item = $('<div/>')[plugin]({'option':'value'});
Sign up to request clarification or add additional context in comments.

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.