var arr = ['comfort','business','miniven','bus']; arr.forEach(function(el){ $('#'+el+'show').click(function(){ $('#'+el+'container').show(); arr.forEach(function(elt){ if(elt!=el)$('#'+elt+'container').hide(); }); }); });