For Each Statement & JQuery .hover
I am a javascript newbie and trying to write a script to create hover-over popups for a product page... It works like a charm when I assign it a solo "div#id" and "a#id", however I need it to work on multiple objects.
I can't use a class because then everything with the classname pops up at the same time. So each popup HAS TO have a unique ID.
I am trying to write a for each statement, but it doesn't seem to be working... any ideas... or better ways to execute this...
This is the one that works (but only for one):
<script type='text/javascript'>
$(document).ready(function(){
$( '
a#popup' ).hover(function(){
$(
'div#popupBox' ).fadeIn(500);
},function(){
$(
'div#popupBox' ).fadeOut(500);
});
});
</script>
This is my current for each equiv (Not Working):
<script type='text/javascript'>
for (i = 1; i < 12; i++){
var
this_a =
'a#popup' + i;
var
this_div =
'div#popupBox' + i;
$(
this_a ).hover(function(){
$(
this_div ).fadeIn(500);
},function(){
$(
this_div ).fadeOut(500);
});
}
</script>