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>