in building a navigation system, I would like to use a system where I have, say, four links which naturally are different pages. Initially, all links are, say, blue. When clicking on the first link, it would change its color to, say, green. Clicking on the second link, the first link would change back to blue and the second link from blue to green. An so forth.
I am a newbie when it comes to Javascript and in searching, haven't found anything that would satisfy the specific need I have. I'm also not sure if this can be done in Javascript or do I need to have PHP involved also (which is what I'm using for back-end stuff).
I have the following code but I doubt it will work:
Expand|Select|Wrap|Line Numbers
- function Colorize(element) {
- if( document.getElementById )
- document.getElementById(element).color = "#0f0";
- else if( document.all )
- document.all[element].color = "#f00";
- }
Expand|Select|Wrap|Line Numbers
- <div id="navi">
- <a id="link_1" href="page1.php" onClick="return Colorize('link_1')">one</a>
- <a id="link_2" href="page2.php" onClick="return Colorize('link_2')">two</a>
- <a id="link_3" href="page3.php" onClick="return Colorize('link_3')">three</a>
- <a id="link_4" href="page4.php" onClick="return Colorize('link_4')">four</a>
- </div>