$(function() { var urlNow = window.location.href; urlNow = urlNow.split("-")[0]; $('a[href="'+urlNow+'"]').addClass('active'); });