Reputation: 764
Assuming I have a jquery collection or a variable representing a jquery collection and I want to chain a jquery method to an item of the collection. For example:
$('#container').fadeIn();
So far no problem. But what if I don't know the name of the method to chain yet at the time the script is loaded because the method name is the value of an item in a configuration object?
I hope it's clear what I mean. Thank's in advance.
Upvotes: 0
Views: 82
Reputation: 18008
Use Bracket Notation:
var dynamicMethodName = "fadeIn"; // from configuration
$('#container')[dynamicMethodName]();
Upvotes: 2
Reputation: 59232
You can always use bracket notation:
$('#container')["fadeIn"]();
So, store the function name in a variable and then use it.
var funcName = "fadeIn";
$('#container')[funcName]();
Upvotes: 0