Creating "Active" link styles

They have: 426 posts

Joined: Feb 2005

HI,

I want to create an "Active" link style. So when a user clicks on a link the style of that link changes to reflect that it is active - it has a different style to other links.

I know i can do this with php but this seems like a long winded effort to have loads of if statements in my menu list.

I figured if i have some javascript at the top of each page that looks at the current url and matches it up against an href"" then styles that link?

Unfortunately i cannot find any javascript functions that can help me.

Can anyone recommend anything or point me in the right direction?

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

What??? Why are you trying to use PHP to do this? Unless I'm misunderstanding the question. The CSS :active pseudo-class should be enough, shouldn't it? Or are you trying to do something else?

Or, are you tring to mark links to the page that the user is on? We have an article on several techniques for this at A Padded Cell:

3 Ways to Highlight Links to the Current Page with CSS

They have: 426 posts

Joined: Feb 2005

These are good articles, thanks.

No active only works when clicking on the link, i want the link to have a different style when viewing that page.

The articles you provided are what i was looking for: Thanks.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.