Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


6,232 Points

active state in nav

Hi guys I am trying to have a background image to indicate which page you are viewing.

My php knowledge is pretty poor so I am looking to do this with jquery/java.

I want to addClass of Active when on the present page.

<ul> <li> <a href="/about-us">About Us</a></li> <li> <a href="/categories">Categories</a></li> <li> <a href="/for-the-media">For the Media</a></li> <li> <a href="/contact-us">Contact us</a></li> </ul>

How would I would i do this?

many thanks!

4 Answers

Calvin Nix
Calvin Nix
43,828 Points

Hey William,

For a starting point I would recommend using JQuery's filter() method.

thanks, Calvin

Hi I know you said your PHP is pretty poor - however there is only a small amount in this article - my PHP is rubbish but I have been able to use this on a number of occasions


6,232 Points

Thanks guys, I'll give that a go tomorrow graham when my brain is fresh!

No problem William. Let me know how you get on.