Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1363 How can I change the background color of text in the normal flow of the page?

You are here: irt.org | FAQ | DHTML | Q1363 [ previous next ]

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>

©2018 Martin Webb