-2

My website is split into various categories. In each category, there are articles. I'm trying to add an active class to both the category page, which is a grid menu of all of the articles, as well as each article page within that category. The solutions I have seen compare your current url with the url attached to the navigation link. That solution would work for the category grid page, but not the article pages. To make things a little more complicated, the path for the grid page is /category, but the path for the articles within that category is /article/category/article-name.

Is there a way for me to place an active class on a menu link that relates to all articles within a category as well as the category grid page? I'd prefer a JQuery solution, if possible.

Vishnu Bhadoriya
  • 1,655
  • 1
  • 20
  • 28
Kellen
  • 1,072
  • 2
  • 15
  • 32
  • 1
    possible dublicate - http://stackoverflow.com/questions/4597050/how-to-check-if-the-url-contains-a-given-string – Stender Aug 24 '16 at 13:56

1 Answers1

0
$(document).ready(function () {
 if (/category/.test(window.location.href)){
    //add the active class
 } else if (/article-name/.test(window.location.href)){
   //add the active class
 }
});

something like this?

Stender
  • 2,446
  • 1
  • 14
  • 22