How to call jQuery function by its name. For example:
var fn = 'hide',
myObj = $("#smth");
// here I want to hide myObj ( $("#smth").hide() )
// my variants were:
// fn.call(myObj) - doesn't work
// myObj.fn() - doesn't work (I've not expected, just tried =) )
Access the function as you would access any other member of myObj
using a variable name, and then simply call it:
var fn = 'hide',
myObj = $("#smth");
(myObj[fn])();
Do this:
var fn = 'hide',
myObj = $("#smth");
myObj[fn]();
Cheers
精彩评论