Simplify my JS code

I suggest that you could change the tags to something like:



Accueil


In the javascript, you can have a hash table called rels to put all the complicated dependencies between your links



;(function(){
var rels = {
'entreprise': ['entreprise', 'realisations'],
'services': ['services', 'realisations'],
...
}

function checkRels(link){
var other = rels[link];
for(var i = 0; i < other.length; i++){
if($('#menu-top li a[data-link="' + other[i] + '"]').is('.active')){
return false;
}
}
return true;
}

$("#menu-top li a").mouseover(function() {
var link = $(this).attr('data-link');
if(!checkRels(link))return false;
$(this).removeClass("rightactive");
$(this).addClass("righthover");
}).mouseout(function(){
var link = $(this).attr('data-link');
if(!checkRels(link))return false;
$(this).removeClass("righthover");
$(this).addClass("rightactive");
});
}())


When you want to change the dependencies or add more, you can simply adjust the rels, instead of changing a lot of codes.


More: