# Help With JavaScript

**URL:** <https://www.ruby-forum.com/t/help-with-javascript/105286>\
**Category:** Radiant CMS\
**Created:** [May 28, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/help-with-javascript/105286 "2007-05-28T13:26:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![olicat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a8b319/32.png) [@olicat](https://www.ruby-forum.com/u/olicat)\
**Post date:** [May 28, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/help-with-javascript/105286/1 "2007-05-28T13:26:06Z")

</div>

Hi -

Thanks for the useful information about how to add JavaScript to a page.

I know it’s not quite on the topic of RoR, but I need a little bit of  
help with my JavaScript.

My HTML is as follows:

- [Welcome](http://www.spongenewmedia.co.uk/ "Return to the home page")
- [Blog](https://www.ruby-forum.com/blog/ "Read the latest blog entries")
- [Contact](https://www.ruby-forum.com/contact/ "Contact information for Oliver C.")

What I want to do is apply the class “selected” to certain links using  
JavaScript. The purpose of this is to show what page you are currently  
on.

The JavaScript I currently have is this:

However, this only applies the class of “selected” to the

- item. How  
to use the getElementById function to select the actual hyperlink?

Many thanks in advance!

* * *

Try [Live.com](http://Live.com): where your online world comes together - with news,  
sports, weather, and much more.  
[Outlook – free personal email and calendar from Microsoft](http://www.live.com/getstarted)

---

<div class="post-metadata">

**Author:** ![olicat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a8b319/32.png) [@olicat](https://www.ruby-forum.com/u/olicat)\
**Post date:** [May 28, 2007, 1:33pm UTC](https://www.ruby-forum.com/t/help-with-javascript/105286/2 "2007-05-28T13:33:08Z")

</div>

Why do you need to get the actual hyperlink? If you just want to  
indicate what page you are on, use “li.selected a” as your CSS  
selector and it will find the proper link. I do this all the time for  
navigation lists.

Otherwise, you will have to have an id on the actual link, not the  
list element. This would of course work at well, but then you have to  
assign an id to you link in the navigation code. Not very clear I  
know, but maybe this helps…

Keith B.  
Tel: +49-7731-79838380  
removed\_email\_address@domain.invalid  
[http://keithbingman.com](http://keithbingman.com)
