...

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



pvz
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

newmand2
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'
}
</script>

<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.

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

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

pvz
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:

onmouseover="changestyle('link2','#ffffff')"

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


<script type="text/javascript">
function lite(name, color) {
document.getElementById(name).style.color=color;
}
</script>
...
<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.

newmand2
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">');
break;

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

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

default:
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum