If you can't tell by my other questions, I'm a self-taught newb. I'm trying to consolidate some of my js code. I have 2 divs, with class a0 and a1. I'd like to attach a mouseenter event to each (same event).
Here's my fiddle, which is (hopefully) self-explanatory. .a0 and .a1 are my original code and .f0 and .f1 represents my (failed) attempt to consolidate. Why can't I do a "for" loop (or, if I can, why do I always end up w/ value of "2" for i?)?
(If there's a way I can do it in jquery, that's fine)
See above fiddle for full demo:
$(".a0").on("mouseenter",function(){
$(this).html("value: 0");
});
$(".a1").on("mouseenter",function(){
$(this).html("value: 1");
});
/* my failed attempt to consolidate the above code */
for (var i=0; i<2; i++){
$(".f"+i).on("mouseenter",function(){
$(this).html("value: "+ i);
});
}