[thelist] Is it possible to change the table cell bgcolor by JavaScript?

jeff jeff at members.evolt.org
Wed Jan 24 06:25:31 CST 2001


ppk,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Peter-Paul Koch
:
: > The problem is to address the cell object
: > in JavaScript. Is it possible anyway?
:
: The simplest solution by far (but it requires
: lots of code) is:
:
: <TD onClick="this.bgColor = '#cc0000'">stuff</TD>
:
: and onClick the background colour changes.
: Works in IE4+ and NN6.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the trouble with this example is that you'll end up with all the td's with
their background color changed.  that's fine if that's what you're looking
to do.  however, if you want to turn off the previously selected td you're
going to have to store a reference to that object so you know which one to
switch back when a new one is clicked.  at that point you're just better off
using a function.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Nothing will work in NN4, because it can't
: change the bgcolor of a TD.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

that's not even the root of the problem.  the root of the problem is that
nn4 doesn't recognize any event handlers on <table>, <tr>, or <td> tags (and
a whole bunch of others, for that matter).  so, it wouldn't even see the
onClick event to begin with (something to keep in mind when writing this
cause it will already fail gracefully for nn4 users, a rather odd
occurrence).

thanks,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list