There exist some concept like variables variable to print variable names or call functions dynamically:
http://php.net/manual/en/language.variables.variable.php
Thanks in advance.
The closest JavaScript equivalent is bracket notation, for example:
var obj = { myMethod: function() { alert("Hello!"); } };
var func = "myMethod";
obj[func](); //equal to obj.myMethod();
You can test it out here, in JavaScript calling these two is equivalent:
object.property
object["property"];
And the latter allows you to use a variable, to get any property or method you want.
To be clear this is a JavaScript behavior, there's nothing specific to jQuery about it.
In javascript you can use a similar aproach.
$a = "hello";
$['hello'] = 'world';
$[$a];
alert($a + " " + $[$a]); // alerts "hello world"
See in jsfiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With