I’m having trouble passing an array into an event handler.
This does not work:
Code:
var lightbulb = [1,1,1,0,1,0]
var banana = [0,0,1,1,0,1]
function changetextimage(arr){
for(var i=0;i<5;i++){
var pixel = document.getElementById(“text”+i);
if (arr) {
pixel.style.color=”#000000″;
}
else {
pixel.style.color=”#FFFFFF”;
}
}
}
$(‘#lightbulbpicture’).mouseover(changetextimage(lightbulb));
$(‘#bananapicture’).mouseover(changetextimage(banana));
This does work:
Code:
var lightbulb = [1,1,1,0,1,0]
var banana = [0,0,1,1,0,1]
function changetextimage1(){
for(var i=0;i<5;i++){
var pixel = document.getElementById(“text”+i);
if (lightbulb) {
pixel.style.color=”#000000″;
}
else {
pixel.style.color=”#FFFFFF”;
}
}
}
function changetextimage2(){
for(var i=0;i<5;i++){
var pixel = document.getElementById(“text”+i);
if (banana) {
pixel.style.color=”#000000″;
}
else {
pixel.style.color=”#FFFFFF”;
}
}
}
$(‘#lightbulbpicture’).mouseover(changetextimage1);
$(‘#bananapicture’).mouseover(changetextimage2);
I have a whole bunch of these arrays (which are about 4000 characters longer) that I want to pass into this function so I just want to pass each as an argument rather than write each function out.