Forum Moderators: open

Message Too Old, No Replies

How to simulate a rollover

Linking two anchors in code

         

RossWal

5:42 am on May 27, 2007 (gmt 0)

10+ Year Member



I'm not JS accomplished at all and I've been struggling with this. I have two anchors adjacent to one another. They link to the same place, but are separated because they have different styles. When one is rolled over - I would like to see the rollover affect on the adjacent one too. In this way they will look like one element to the user.

 

<a href="http://example.com" onmouseover="fred.setAttribute('class','rolledover')">Hello</a>

<A id=fred name=fred href="http://example.com">Goodbye</A>

I tried a number of similar things... pointless to post them here since the don't work.....

Can anyone help?

mehh

5:46 pm on May 28, 2007 (gmt 0)

10+ Year Member



something like this?

<html>
<head>
<title>Test</title>
</head>
<body>
<style type="text/css">
.rolled{background-color:#0f0}
.normal{background-color:#f0f}
</style>
<a href="#" id="hello" class="normal" rel="rollover">Hi</a>
<a href="#" id="hello2" class="normal" rel="rollover">Hi</a>
<script type="text/javascript">
<!--
function roll(id,c)
{
var f=document.getElementById(id);
var s=document.getElementById((id.substr(id.length-1)=="2")?id.substr(0,id.length-1):id+"2");
f.className=c;
s.className=c;
}
var l=document.links;
var ll=l.length;
for(var i=0;i<ll;i++)
{
if(l[i].rel=="rollover")
{
l[i].onmouseover=function(){roll(this.id,"rolled");};
l[i].onmouseout =function(){roll(this.id,"normal")};
}
}
//-->
</script>
</body>
</html>

RossWal

8:04 pm on May 30, 2007 (gmt 0)

10+ Year Member



Yes! That is exactly it.

Thanks.