Skip to content

Add Active Navigation Class Based on URL

Ideally you output this class from the server side, but if you can’t…

Let’s say you have navigation like this:

And you are at the URL:

http://yoursite.com/about/team/

And you want the About link to get a class of “active” so you can visually indicate it’s the active navigation.

Essentially that will match links in the nav who’s href attribute begins with “/about” (or whatever the secondary directory happens to be).

One Comment

  1. Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.

Leave a Reply

Your email address will not be published.

Share via
Copy link
Powered by Social Snap