John R Perry John R Perry - 5 months ago 15
CSS Question

jQuery add class .active on menu within subfolders

I was able to find a solid solution on how to add an 'active' class to menu items based on the url of the page:

var page = window.location.pathname,
find = new RegExp(page == '/' ? window.location.origin + '/?jQuery' : page.replace(/\/jQuery/,''));
jQuery('nav a').each(function(){

This, however, does not work with links within subfolders and I can't seem to figure out a way to make it work. What am I missing?


This is what I use and it works for menu items in my subfolders

$(".menu-item").each(function() {
  if (this.href == window.location.href) {