I have a set of divs:
<div id="div_01">ASD</div>
<div id="div_02">ASD</div>
<div id="div_03">ASD</div>
I want to create a set of .click functions for those divs:
I tried this:
for (var i = 1; i < 4; i++) {
var picName = "#BSViolenceDiv_0" + i.toString();
//alert("\nI have for i: " + i + ": " + picName);
$("#div_0" + i.toString()).click(function(){
$("#div_0" + i.toString()).animate({opacity:1}, 1000);
});
}
It does not work because i ends up being 3.
What did I do wrong?
clickevent handlers. Just use a class and bind that click handler to that class instead just like the answer of @Zakaria.