1

This question is related to one I asked previously at Using Mouseenter / MouseLeave to Change Div in JavaScript.

As answered, I had an index closure problem. I had a new function use an existing index, and the answer provided made perfect sense - except for one part.

After this:

for (var i = 0; i < radialDivList.length; i++) {
    if (!radialDivList[i]) continue; //skip null, undefined and non-existent elements
    if (!radialDivList.hasOwnProperty(i)) continue; //skip inherited properties
    smallID[i] = radialDivList[i].id; //assign the list of four divs to the smallID array;
    largeID[i] = smallID[i] + 'Full'; // add "Full" to each smallID element to make a largeID element
}

I had

$('#' + smallID[i]).mouseenter(function () { //works for all four radial menu divs when mouse enters
    alert(largeID[i]); // undefined
    alert(largeID); // gives expected output of full array

I now understand why the largeID index is undefined, but I don't understand why the mouseenter function works for all four radial menu items. My understanding of index closure makes me think that the value of [i] for the smallID[i].mouseenter function will be "3", given the result of the previous for loop. If so, why do all four menu sections trigger a mouseenter event properly?

Thanks for any help you are willing to provide!

@programmerGuy - care to further your explanation from the previous question?

Community
  • 1
  • 1
boucains
  • 25
  • 6
  • 4
    there is no way to answer questions like these unless we can see the full contenxt of all variables referenced and where and how they are defined. This is the nature of closures. – Hogan Jan 04 '16 at 21:15
  • You are binding mouseenter in for loop, right? If ya, then you posted unrelevant code. If not, provide simple MCVE replicating issue – A. Wolff Jan 04 '16 at 21:29
  • @hogan My apologies. I thought that the specific nature of the question would allow the code fragment to be sufficiently informative. The original code has been replaced, but I will pull it out of Git and repost. Thanks for taking your time to respond! – boucains Jan 05 '16 at 21:18

1 Answers1

0

This seems to be related to a browser caching issue. After a reboot, this code no longer triggers a mouseenter event.

boucains
  • 25
  • 6