Pete Winter
asked on
If current page url
My code to add a class based on the current page is not working. Can you help me work out why?
See this url: http://new2.jensonfisher.com/about-us/values/
Look at the sub navigation below the image.
$(document).ready(function() {
$(function(){
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
$('.sub_nav a').each(function(){
// and test its normalized href against the url pathname regexp
if(urlRegExp.test(this.href.replace(/\/$/,''))){
$(this).addClass('sub_nav_active');
}
});
});
});
See this url: http://new2.jensonfisher.com/about-us/values/
Look at the sub navigation below the image.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Such a silly mistake! Thanks for your help.
You are welcome.
ASKER
http://new2.jensonfisher.com/about-us/values/
this is the script in the page: http://new2.jensonfisher.com/wp-content/themes/jensonfisher/js/jf-scripts.js