I am having the code below and javascript's closure together with anonymous functions are giving me a headache.
for (var i = 0, len = sites.length ; i < len ; i++)
{
$("#thumb"+i).click(function() { $("#shader").show(); $("#thumbInfo"+i).show(); alert("#thumbInfo"+i); });
$("#thumbInfo"+i+" .xbutton").click(function() { $("#shader").hide(); $("#thumbInfo"+i).hide(); });
}
Due to closure, i is always 5 (the sites array has 5 elements), so all the click handlers refer to the same id.
Any workaround?
ihardcoded) does it work? I have a feelingiis not the problem.