Entry
How can I use a Link's OnClick to set/change the bgColor of the cell it is in? (pre NN6?)
Jun 12th, 2002 08:04
David Blackledge, Dan Baker,
Most people would say "You can't do that in NN4!"... but not me ;]
For each cell you want to be able to do that with, you have to somehow
give it a style specification with "position:relative"
Easiest is to just put style="position:relative" on the TD tag itself,
but if you have a lot of cells you might want to use classes and/or
selectors like:
TABLE.relativecells TR TD {position:relative}
but you have to play with those a lot in NN4 to get them to work.
Anyhow, once you've done that, in the ONCLICK event of the link (won't
work in a javascript: URL in the HREF... it has a different context,
apparently) you can do something like this:
onclick="bgColor='blue';return false;"
Since our link is in the context of an outer layer now (by setting
position on the TD), all of the layer's properties are available to us
directly... (as long as they don't overlap with the Link's properties,
e.g. x and y, I think.). You can also change the visibility, and a
number of other things.
Watch out for trying to move the layer, though... or re-write its
contents... relatively positioned layers have funny behavior (moving the
layer will move it visually, but the link's active area will still be in
its original location on the page!)
I'm assuming you already know how to do this in IE (and if not, many
people here could probably answer that part).
David.
http://David.Blackledge.com