$(function(){ var url = window.location.href; var a = $('[href="'+url+'"]'); url.indexOf("contacts") == -1 && (a = a.parents("ul").prev()); a.addClass("active") })