Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

williamrossi
williamrossi
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

http://alistapart.com/article/keepingcurrent

williamrossi
williamrossi
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.

G