yourbudweiser
asked on
Change font color onmouseover
I have a bunch of asp.net labels. I change the text color to blue with onmouseover="this.style.co lor='blue' ;" and I change it back to black with onmouseout="this.style.col or='black' ;"
I would like to keep this functionality but also when the label text is clicked, I want it to remain blue. The mouseover effects will still funtion but if I click a different label, the current one will go to black and the new one will be blue.
I already have a function attached to the onclick event as well.
Can this be done?
I would like to keep this functionality but also when the label text is clicked, I want it to remain blue. The mouseover effects will still funtion but if I click a different label, the current one will go to black and the new one will be blue.
I already have a function attached to the onclick event as well.
Can this be done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How about this:
<html>
<head>
<title>Zvonko *</title>
<style>
li.blue {
background-color: cornflowerblue;
}
</style>
<script>
var lAct;
function doHover(theLink){
theLink.className="blue";
}
function doLeave(theLink){
if(lAct!=theLink){
theLink.className="";
}
}
function setLink(theLink){
if(lAct) lAct.className="";
lAct=theLink;
lAct.className="blue";
}
</script>
</head>
<body>
<ul>
<li onmouseover="doHover(this) " onmouseout="doLeave(this)" onClick="setLink(this)" >One</li>
<li onmouseover="doHover(this) " onmouseout="doLeave(this)" onClick="setLink(this)" >Two</li>
<li onmouseover="doHover(this) " onmouseout="doLeave(this)" onClick="setLink(this)" >Three</li>
<li onmouseover="doHover(this) " onmouseout="doLeave(this)" onClick="setLink(this)" >Four</li>
<li onmouseover="doHover(this) " onmouseout="doLeave(this)" onClick="setLink(this)" >Five</li>
</ul>
</body>
</html>
<html>
<head>
<title>Zvonko *</title>
<style>
li.blue {
background-color: cornflowerblue;
}
</style>
<script>
var lAct;
function doHover(theLink){
theLink.className="blue";
}
function doLeave(theLink){
if(lAct!=theLink){
theLink.className="";
}
}
function setLink(theLink){
if(lAct) lAct.className="";
lAct=theLink;
lAct.className="blue";
}
</script>
</head>
<body>
<ul>
<li onmouseover="doHover(this)
<li onmouseover="doHover(this)
<li onmouseover="doHover(this)
<li onmouseover="doHover(this)
<li onmouseover="doHover(this)
</ul>
</body>
</html>
Sorry, hadn't seen basicinstinct's post, should have refreshed...
lol @ cornflowerblue
:)
yours is quite different to mine tho tname, certainly worth posting alongside mine as it gives yourbudweiser more options to consider...
ASKER
these look great, thanks so much for responding. i'll need some time to check out the code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script>
function changeCol(obj){
var links = document.getElementsByTagN
for (var i=0; i<links.length; i++) {
if (links[i].className=='high
links[i].className='plain'
}
obj.className='highlighted
}
</script>
<style>
#content {width:300px; overflow:hidden; margin:0 auto;}
ul#tabs {float:left; width:240px; list-style: none; margin:0; padding:0; height:20px;}
ul#tabs li {list-style: none; display:inline; float:left; margin:0 4px; }
ul#tabs li a,
a.plain {display:block; background:#fff; color:#000; }
ul#tabs li a:hover,
ul#tabs li a.highlighted {background:#abc; color:#00f;}
</style>
</head>
<body>
<div id="content">
<ul id="tabs">
<li><a class="plain" href="#" onclick="changeCol(this);"
<li><a class="plain" href="#" onclick="changeCol(this); ">Tab two</a></li>
<li><a class="plain" href="#" onclick="changeCol(this);"
</ul>
</div>
</body>
</html>