C
Chris Riesbeck
I need to remove colors put on links with Javascript so that CSS hover
works on uncolored links. Both background color and transparent turn
off the hover effect, and null doesn't remove the color. I discovered
that the empty string worked in IE 6, Mozilla 1.1 and Opera 7. But is
that legal? If not, what is the right way? Here's a toy demo of the
working page:
<html><head><title>Example</title>
<style type="text/css">
a:hover { background-color: #FFFF66;}
body { background-color: #FFFFFF; font-size: 24pt;}
</style>
<script type="text/javascript">
var oldLink;
function select(link) {
if (oldLink) oldLink.style.backgroundColor = ""; // OK???
oldLink = link;
link.style.backgroundColor = "#CCCC33";
}
</script>
</head>
<body>
<p>
<a href="#" onclick="select(this)">Line 1</a><br>
<a href="#" onclick="select(this)">Line 2</a><br>
<a href="#" onclick="select(this)">Line 3</a><br>
<a href="#" onclick="select(this)">Line 4</a><br>
<a href="#" onclick="select(this)">Line 5</a><br>
</p>
</body>
</html>
works on uncolored links. Both background color and transparent turn
off the hover effect, and null doesn't remove the color. I discovered
that the empty string worked in IE 6, Mozilla 1.1 and Opera 7. But is
that legal? If not, what is the right way? Here's a toy demo of the
working page:
<html><head><title>Example</title>
<style type="text/css">
a:hover { background-color: #FFFF66;}
body { background-color: #FFFFFF; font-size: 24pt;}
</style>
<script type="text/javascript">
var oldLink;
function select(link) {
if (oldLink) oldLink.style.backgroundColor = ""; // OK???
oldLink = link;
link.style.backgroundColor = "#CCCC33";
}
</script>
</head>
<body>
<p>
<a href="#" onclick="select(this)">Line 1</a><br>
<a href="#" onclick="select(this)">Line 2</a><br>
<a href="#" onclick="select(this)">Line 3</a><br>
<a href="#" onclick="select(this)">Line 4</a><br>
<a href="#" onclick="select(this)">Line 5</a><br>
</p>
</body>
</html>