[thelist] for loop, array and mouseover teazer
Lee Kowalkowski
lee.kowalkowski at googlemail.com
Thu Sep 13 03:01:50 CDT 2007
On 12/09/2007, Chris Price <chris.price at choctaw.co.uk> wrote:
> Lee Kowalkowski wrote:
> > MyPointer.onmouseover = new Function("MyWorld.nodeValue = MyDesc[" +
> > i + "] + ' world'");
> >
> > ... because 'i' will be evaluated when the function is defined and
> > therefore essentially be a constant value.
> >
> Thanks Lee, but now I get the error MyWorld and MyDesc are not defined.
Oh, I see - you've got more of a scope issue than I first thought.
Solving the scope of 'i' broke the closure over MyWorld and MyDesc that you had.
I'm sure you can fetch the MyWorld element from its ID, but MyDesc is different.
In these stuations I am more inclined to do the following:
function mouseover()
{
var myWorld = document.getElementById('<myWorldId>');
myWorld.nodeValue = this.desc + ' world';
}
for (i in MyDesc)
{
var MyPointer = document.getElementById(i)
MyPointer.desc = MyDesc[i];
MyPointer.onmouseover = mouseover;
}
--
Lee
More information about the thelist
mailing list