View Full Version : Changing the style (the color) of another link?

02-15-2004, 04:13 PM
How can I change the style (the color) of another link onmouseover?
something like this:
<a name="link1" href="page1.htm" onmouseover="changestyle('link2')">link1</a>
<a name="link2" href="page2.htm">link2</a>
Hope you can help! Thanks/P

02-15-2004, 04:18 PM
perhaps this may come in handy?

<script type="text/javascript">
function tog(elemID){
document.getElementById(elemID).style.display =
(document.getElementById(elemID).style.display == 'none') ?
'block' : 'none'

<a href="#" onclick="tog('div1')">Style 1</a>
<a href="#" onclick="tog('div2')">Stlye 2</a>
<a href="#" onclick="tog('div3')">Style 3</a>
<div id="div1" class="class1"><a href="link.htm">THE SAME LINK</a></div>
<div id="div2" class="class2"><a href="link.htm">THE SAME LINK</a></div>
<div id="div3" class="class3"><a href="link.htm">THE SAME LINK</a></div>

I know its not EXACTLY what you specified but its all i could think of.

02-15-2004, 04:22 PM
Something like this?
window.onload = function () {
document.getElementById('changeomo').onmouseover = function(){
document.getElementById('changedomo').style.color = '#f00'
<a href="#" id="changeomo">Hello</a>
<a href="#" id="changedomo">World</a>

Paul Jr
02-15-2004, 06:54 PM
Ah, silly me, mis-read the post. :o

02-16-2004, 10:16 AM
Thanks. But is there really no way that I can define which link to change the style of in each case... Something like:


Paul Jr
02-17-2004, 04:21 AM
This is kinda rough draft...

<script type="text/javascript">
function lite(name, color) {
<a href="#" onmouseover="lite('link2', '#FFFFFF');" onmouseout="lite('link2', '#000000');">Link</a>
<a href="#" id="link2">Link 2</a>

That also requires you to give each link you want to change an ID. So I'm sure there's a better solution out there.

02-17-2004, 11:12 AM
Just a quick question... Couldn't you just keep the links the same colour? Why is it that you want to do this? Not being nasty but just wondering.

In PHP (I don't know whether you use PHP or have access to it etc) you can (i think) do this:

switch($style) {

case 'style1':
echo ('<link href="style1.css" rel="stylesheet" type="text/css">');

case 'style2':
echo ('<link href="style2.css" rel="stylesheet" type="text/css">');

case 'style3':
echo ('<link href="style3.css" rel="stylesheet" type="text/css">');

echo ('<link href="style.css" rel="stylesheet" type="text/css">');

And then the links could be www.yourdomain.com/index.php?style=style1

Just a thought