Simplify my JS code

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


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

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;
var link = $(this).attr('data-link');
if(!checkRels(link))return false;

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