a").each(function() { if (jQuery(this).attr('href') === window.location.pathname) { jQuery(this).addClass('active'); } else { var s = jQuery(this).attr("href"); if (s) { if (s.indexOf(".") > -1) { s = s.substring(0, s.indexOf('.')); } if ((window.location.pathname).indexOf(s) > -1) { jQuery(this).addClass('active'); } } } }); });