Calling dynamic jQuery plugin with dynamic parameters in Javascript -


suppose need dynamically construct plugin calls such

$('#mydiv').myplugin({a:'a',b:'b'}); 

will like:

function funccallbuilder(selector, func, opts){   //dynamically construct plugin call here } 

using:

funccallbuilder('#mydiv', 'myplugin', {a:'a',b:'b'}); 

can point out correct way of doing this?

not sure if understand question, if want first , third code snippet have same effect, use apply:

function funccallbuilder(selector, func, opts){     func.apply($(selector), [opts]); } 

or, if want pass function string instead of function object (not point imho):

function funccallbuilder(selector, func, opts){     $.fn[func].apply($(selector), [opts]); } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -