Superfish – Add active class to current menu link

Superfish is a jQuery plugin for creating drop down menu. You can download it @ GitHub – karevn / superfish.

It works well but there is no CSS class for identifying the menu item of the current page. Luckily i found a solution in StackOverflow.

The following jQuery code will find out the menu item which match the current URL and add the active class to it.

<script type="text/javascript">
var path = window.location.pathname.split('/');
path = path[path.length-1];
if (path !== undefined) {
    .find("a[href$='" + path + "']") // gets all links that match the href
    .parents('li')  // gets all list items that are ancestors of the link
    .children('a')  // walks down one level from all selected li's


Done =)

Reference: StackOverflow – Active links jquery superfish


6 thoughts on “Superfish – Add active class to current menu link”

  1. This solution doesn’t seems to work for me. Where exactly you have put this piece of code ? In your HTML file or JS file?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.