Forum: Radiant CMS Help With JavaScript

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9c9ef21b37c2ef38425ed036e34d1658?d=identicon&s=25 Oliver Coningham (Guest)
on 2007-05-28 13:26
(Received via mailing list)
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:
<ul id="nav">      <li id="nav-welcome"><a
href="" title="Return to the home
page">Welcome</a></li>      <li id="nav-blog"><a href="/blog/"
title="Read the latest blog entries">Blog</a></li>      <li
id="nav-contact"><a href="/contact/" title="Contact information for
Oliver Coningham">Contact</a></li></ul>

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

The JavaScript I currently have is this:

<script type="text/javascript">
document.getElementById('nav-blog').className='selected'; </script>

However, this only applies the class of "selected" to the <li> item. How
to use the getElementById function to select the actual hyperlink?

Many thanks in advance!

Try where your online world comes together - with news,
sports, weather, and much more.
E91bbb5eae81347ed57880eea764c0f9?d=identicon&s=25 Keith Bingman (Guest)
on 2007-05-28 13:33
(Received via mailing list)
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 Bingman
Tel: +49-7731-79838380
This topic is locked and can not be replied to.