We have written some function in jquery. When the user clicks on each div, we need to dynamically call each function.
<div class="test" id="test1"></div>
<div class="test" id="test2"></div>
function test1(){
alert('test1');
}
function test2(){
alert('test2');
}
$(".test").on("click",function(){
var function_name=$(this).attr("id");
window[function_name]();
});
But this code does not work, error - this window [function_name] is not a function. How to solve this problem?
Also suggest another 2,3 methods
user7118434
source
share