I'm trying to run series of functions i placed on a variable.
Here's a (demo)
Code:
function pass_me(x) {
alert(x);
};
var colors = new Array();
var colors = ["pass_me('yellow');", "pass_me('green');", "pass_me('blue');"]
for(var i = 0; i <= colors.length; i++) {
window[colors[i]]();
}
unfortunately, I can't make it run. Any idea what's wrong in my code?
Thanks
The story behind the array variable of function, is because i copied it from a dynamic element. This way it will only run what function is already in the page. So if pass_me("red") is not present, it will not be run.
Example:
<img src="img/something.jpg" ondblclick="pass_me("yellow")" />
<img src="img/something.jpg" ondblclick="pass_me("green")" />
<img src="img/something.jpg" ondblclick="pass_me("blue")" />
then I just use:
jQuery("td img").each(function(){
colors.push(jQuery(this).attr("ondblclick"));
})
"pass_me('yellow');"is a string, you'll have to either eval it or parse it out.var colorsis unnecessary - it just gets overwritten when you create a new array on the next line.