Reputation: 3
I want a function to be invoked when I click on a div
.
I have the functions arti1()
,arti2()
,arti3()
. So, if I click that div
, the function on that div
as follows:
<div class="random" onclick="rondom()">Random</div></div>
function rondom(){
var rndm = Math.floor(Math.random() * 8) + 1;
arti+rndm+().css("display", "block");
}
How can I display that random function?
Upvotes: 0
Views: 56
Reputation: 121
You can use eval () or put your functions inside an array
function rondom(){
var rndm = Math.floor(Math.random() * 8) + 1;
eval ('arti'+rndm+'().css("display", "block")');
}
Upvotes: 0
Reputation:
<div class="random" onclick="rondom()">Random</div></div>
function rondom(){
var rndm = Math.floor(Math.random() * 8) + 1;
eval("arti"+rndm+"().css(\"display\", \"block\")");
}
Upvotes: 1