javascript onclick set to variable function name? -
javascript onclick set to variable function name? -
is possible utilize javascript set click event variable function name?
i want dynamically set each of selected elements functions names declared elsewhere. these functions class methods. don't know if why it's not working.
i know funky monkey stuff, it's preferable alternative of using switch, functions have parse through.
function name get
// lastly part of string var x = strname.split("_"); var y = x[x.length - 1];
this works
holder[j].onclick = function(){ini['add']();};
this not, reason
holder[j].onclick = function(){ini[y]();}; // checked: y == 'add' in test
i found not work. onclick not set function want be, statement
ini[y]();
as y no longer in scope after setup finish (and if was, there's no saying right y, has different value each iteration), i've had pull out create determine function on fly.
using this:
holder[j].onclick = function(){clickmaster(this);};
then this:
function clickmaster(ele){ // pull out strname based on ele var x = strname.split("_"); var y = x[x.length - 1]; ini[y](); }
rather trying set onclick straight class method.
javascript onclick naming-conventions
Comments
Post a Comment