|
Q1363 How can I change the background color of text in the normal flow of the page?
irt.org | Knowledge Base | DHTML | Q1363 [ previous next ]
Q1363 How can I change the background color of text in the normal flow of the page?
Try:
<html>
<head>
<script language="JavaScript"><!--
document.write('<style>');
if (document.layers) document.write('.region { position: relative; }');
document.write('<\/style>');
//--></script>
<script language="JavaScript"><!--
var original = true;
function changeColor(id) {
if (original) {
if (document.getElementById) document.getElementById(id).style.backgroundColor = 'red';
else if (document.layers) document[id].bgColor = 'green';
else if (document.all) document.all[id].style.backgroundColor = 'blue';
}
else {
if (document.getElementById) document.getElementById(id).style.backgroundColor = 'white';
else if (document.layers) document[id].bgColor = 'white';
else if (document.all) document.all[id].style.backgroundColor = 'white';
}
original = !original;
}
//--></script>
</head>
<body>
<p>
Text prior to region <span id="myspan" class="region">text in region</span> text after region.
</p>
<p>
<a href="javascript:changeColor('myspan');void 0">change color</a>
</p>
</body>
</html>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.