Revision: 47194
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 2, 2011 06:01 by ronal
Initial Code
var url = window.location.pathname, urlRegExp = new RegExp(url.replace(/\/$/,'') + "$"); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there // now grab every link from the navigation jQuery('#nav li').each(function(){ // and test its normalized href against the url pathname regexp if(urlRegExp.test(this.href.replace(/\/$/,''))){ jQuery(this).addClass('active'); } }); });
Initial URL
Initial Description
Initial Title
jQuery add ACTIVE class
Initial Tags
link, jquery
Initial Language
JavaScript