client side takes in some images from server, then base on that create thumbnails pictures. When user click on these thumbnails it does something. However the number of images sent from server can be any number. So now I am stuck, I don't know how to generate click function without writing each one out like below. Can someone guide me to the right direction without giving me the actual answer?
$("#thumb-0").click(function(){
index=0;
switchHouse(index);
});
$("#thumb-1").click(function(){
index=1;
switchHouse(index);
});
$("#thumb-2").click(function(){
index=2;
switchHouse(index);
});
...
$("#thumb-X").click(function(){
index=arrayLength;
switchHouse(index);
});
I tried the following, but doesnt work obviously:
for (var i=0; i<topHouse.length; i++){
$("#thumb"+i).click(function(){
index=i;
switchHouse(index);
});
}
"#thumb"+iit should be"#thumb-"+i