[thelist] JavaScript - searching for link and comparing

Christian Heilmann lists at onlinetools.org
Tue Dec 21 17:36:15 CST 2004


Pringle, Ron wrote:

>Hi all-
>
>I'm a neophyte when it comes to Javascript. I'm trying to write some code
>that will search through my nav for a link matching the current page, and
>then write a css class to the containing <li> to style it as the current
>page the user is on.
>
>I've googled around looking at examples of getElementByID, but don't see
>examples that match what I'm trying to do.
>
>  
>
Suggestion: Don't bother. A navigation highlight should be a non-link, 
to avoid pages linking to themselves. You could achieve that via 
Javascript, too, but it is neither accessible nor usable.

If you really want to do it, you can compare the link to the current 
window location and then set the LI class:
http://www.onlinetools.org/tests/scripnavhighlight.html

HTH
Chris






More information about the thelist mailing list