/    Sign up×
Community /Pin to ProfileBookmark

link has to return to previous color after clicking new one…

hi,
the problem is: the link’s color must stay #ffffff after klicking onto it (working)

and [B]return back [/B] to #999999 as soon
[B]as one clicks onto ANOTHER link[/B]. (don’t know how to do that)

the result should be: only the last used link gets marked #ffffff.

a [B]written solution [/B] would be helpful!
thx for your help
vaddibaer

[QUOTE]

<style type=”text/css”>
a:hover
{
color: #FFFFFF;
}
</style>

<SCRIPT type=text/javascript>
function changeBg(linkObj)
{
linkObj.style.color = “#ffffff”;
}
</SCRIPT>

<body bgcolor=”#203040″ text=”#999999″ link=”#999999″ alink=#999999 vlink=#999999>

<a href=”#” onclick=changeBg(this);>click1</a>
<a href=”#” onclick=changeBg(this);>click2</a>
<a href=”#” onclick=changeBg(this);>click3</a>

[/QUOTE]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 09.2005 — <style type="text/css">

a{

color: #999999;

}

a:active{

color: #FFFFFF;

}

</style>
Copy linkTweet thisAlerts:
@vaddibaerauthorApr 09.2005 — no bad idea!

a:actice is correct,

but the white color disappears as soon as one klicks somewhere

(e.g. onto the background of my page) or uses another browser...

in other words: it is no 100% solution

any further ideas?
Copy linkTweet thisAlerts:
@BigMoosieApr 09.2005 — you could use javascript to do it, but when you suggest that another browser will ruin it you seem to suggest you need cookies, however do note that browsers use their own cookies thus will not work when a user switches browser. Dont worry though, website designers seem to be the only people who switch browsers alot.
Copy linkTweet thisAlerts:
@VladdyApr 09.2005 — Only if you use links for some extra functionality within the page. Once you left the page you start over. If you are trying to highlight the menu item that corresponds to the page you are currently on, server side scripting is the proper solution.
<i>
</i>&lt;script tested="no" type="text/javascript"&gt;
function initLinks(el)
{ el.currentLink = null;
var myLinks = el.getElementsByTagName('a');
for(var i=0; i&lt;myLinks.length; i++)
{ myLinks[i].onclick = function(e)
{ var lnk = e?e.currentTarget:window.event?this:null;
if(!lnk) return;
var pe = lnk.parentNode;
while(!pe.currentLink)
{ pe = pe.parentNode;
if(/body/i.test(pe.nodeName)) return;
}
pe.currentLink.className = '';
pe.currentLink = lnk;
pe.currentLink.className = 'current';
return false;
};
}
}
&lt;/script&gt;
&lt;style tested="no" type="text/css"&gt;
a
{ background: #999;
}

a.current
{ background: #fff;
}
&lt;/style&gt;
&lt;body onload="initLinks(document.getElementById('myLinks'));"&gt;
&lt;ul id="myLinks"&gt;
&lt;li&gt;&lt;a href="#"&gt;Link 1&lt;/href&gt;
&lt;li&gt;&lt;a href="#"&gt;Link 2&lt;/href&gt;
&lt;li&gt;&lt;a href="#"&gt;Link 3&lt;/href&gt;
&lt;/ul&gt;
Copy linkTweet thisAlerts:
@vwphillipsApr 09.2005 — [code=php]
<SCRIPT type=text/javascript>

var OldlinkObj;

function changeBg(linkObj){
linkObj.style.color='#ffffff';
if (OldlinkObj){
OldlinkObj.style.color = "#999999";
}
OldlinkObj=linkObj;
}
</SCRIPT>



[/code]
Copy linkTweet thisAlerts:
@vaddibaerauthorApr 09.2005 — biggest thank you to

[B]vwphillips[/B]

it works perfectly!!!!! that is exactly what i have been searching for!!!!
×

Success!

Help @vaddibaer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...