Here's my code:
$('.tab_map1 area').hover(function(){
$('#nav1').find('a').stop().toggleClass('hover', 500);
return false;
});
$('.tab_map2 area').hover(function(){
$('#nav2').find('a').stop().toggleClass('hover', 500);
return false;
});
$('.tab_map3 area').hover(function(){
$('#nav3').find('a').stop().toggleClass('hover', 500);
return false;
});
$('.tab_map4 area').hover(function(){
$('#nav4').find('a').stop().toggleClass('hover', 500);
return false;
});
... (there's 8 of them)
I'd like to not repeat the same code multiple times but optimize it somehow. Is there a chance to replace .tab_map1-8 and #nav1-8 with some index value?
I tried:
var n = 8;
$('li.tab_map area').eq(n).hover(function(){
$('#nav').eq(n).find('a').stop().toggleClass('hover', 500);
return false;
});
and:
$("#navibar ul").each(function(index) {
$('.tab_map:eq(' + index + ') area').hover(function(index){
$('#nav:eq(' + index + ')').find('a').stop().toggleClass('hover', 500);
return false;
});
});
Both doesn't work.