I'm trying to work out a trivial issue:
var setListeners = function()
{
for(var i in sliders)
{
sliders[i].switchBtn.click(function()
{
alert(i);
});
}
}
There are three elements in sliders, so 3 switchBtn's are given a click listener. I expected that clicking the first button would alert with a '0', the second a '1' and the third a '2'. However when I press each button, I just get '2'.
Could someone please point out why the value of i is overridden for each new listener function?