Entry
How do I change the bgColor and the fgColor of a table cell?
Sep 10th, 2000 07:39
Martin Honnen,
Only NN6 and IE4+ can change both the background and the foreground
(text) color of a table cell, NN4 can only change the background color;
here is a code example:
<HTML>
<HEAD>
<STYLE>
#aCell {
position: relative;
}
</STYLE>
<SCRIPT>
function setFgColor (color) {
if (document.all)
document.all.aCell.style.color = color;
else if (document.getElementById)
document.getElementById('aCell').style.color = color;
}
function setBgColor (color) {
if (document.all)
document.all.aCell.bgColor = color;
else if (document.getElementById)
document.getElementById('aCell').bgColor = color;
else if (document.layers)
document.aCell.bgColor = color;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<TABLE BORDER="1">
<TR>
<TD>
fgColor:
<INPUT TYPE="text" NAME="fgColor" SIZE="10" VALUE="white">
<INPUT TYPE="button" VALUE="set"
ONCLICK="setFgColor(this.form.fgColor.value)">
<BR>
bgColor:
<INPUT TYPE="text" NAME="bgColor" SIZE="10" VALUE="orange">
<INPUT TYPE="button" VALUE="set"
ONCLICK="setBgColor(this.form.bgColor.value)"
>
</TD>
<TD ID="aCell">
Kibology for all.
<BR>
All for Kibology.
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>