Hello!
Here's a simple bit of code.
It adds the class 'selected' to a link in my menu.Code:function selectLink(elementName) { obj = document.getElementById(elementName); obj.className = "selected"; }
I call it when the pages loads, like this:
It works because I've given the links IDs, like this:HTML Code:<body onload="selectLink('aboutLink1')">
The thing is, I've got another menu that I also want to use the javascript on, it looks like this:HTML Code:<ul class="greyMenu1"> <li><a href="../about" id="aboutLink1">About</a></li> <li><a href="../contact" id="contactLink1">Contact</a></li> <li><a href="../purchase" id="purchaseLink1">Purchase</a></li> </ul>
So, in the onload command I'm calling the javascript once for the first menu and once for the second, like this:HTML Code:<ul class="greyMenu1"> <li><a href="../about" id="aboutLink2">About</a></li> <li><a href="../contact" id="contactLink2">Contact</a></li> <li><a href="../purchase" id="purchaseLink2">Purchase</a></li> </ul>
What I'd like to do is change the javascript so that it can deal with both the elements at once. Effectively I'd like to reduce my HTML to this:HTML Code:<body onload="selectLink('aboutLink1'),selectLink('aboutLink2')">
However, I don't know how to change the javascript to have it deal with more than one element in one go. If anyone knows how, I would really appriciate the lesson.HTML Code:<body onload="selectLink('aboutLink1','aboutLink2')">
Thanks,
Dog



Reply With Quote


Bookmarks