[jQuery] Eval issue ?
[jQuery] Eval issue ?
Hi,
I'm trying to to something in javascript but I don't know how to do
that.
Basicly, I have something like this :
TAGS = new Array(
$(".class"),
$("#foo")
);
B = new Array(
"hey",
"oh"
);
for (var i=0; i < TAGS.length; i++) {
TAGS[i].click( function(event) {
alert(B[i]);
});
}
I would like to alert "hey" when the user clicks on a tag of class
"class" and to alert "oh" when he clicks on a tag of id "foo".
This doesn't work because B[i] takes the "i" when the callback
function is called by jquery (when a click occurs). So it always takes
B[2] in this case (which doesn't exist).
How could I effectively alert B[0] for .class tags and B[1] for #foo
tags ?
Thanks,
Olivier