here a jsfiddle of problem.
clicking on "lizard" should show picture of lizard in both cases.
when replacing "+ entries[index] +" 1 , 6 respectively, works fine. when doing loop, not work anymore.
i have no idea why.
your error expect entries[i] have vaule inside clickevent.
$("#"+ entries[1] +"-choice-c").bind("click", function() { $("#"+ entries[1] +"-lizard").show(); }); the value of entries[i] when click undefined, because value if i 2 (the same length of array).
what need closure keep value of i, , here example:
var items = ["a","b", "c"]; var displayitem = function (i) { window.settimeout(function () { alert(items[i]); }, 100); } (var = 0; < items.length; i++) { displayitem(i); } for code soves problem, got feedle @ian commented.
Comments
Post a Comment