The setBGColor() Method

The setBGColor() method will change the color of the background of the layer.

objectName.setBGColor(color)

Where color is the hexidecimal or color name in quotes.

Example:

mylayer.setBGColor('#C0C0C0')

Warning:

In Netscape there is an issue that will cause problems when using this method. When you set the CSS background-color in Netscape, that property is applied to the background color of the text, not the background color of the entire layer. This is the reason you have to set both the background-color and the layer-background-color properties in order for Netscape to color the entire layer the color you want. All is fine until you try and change the background color using the setBGColor() method. This method will change the layer-background-color property leaving the text with your original background color.

There are ways around this problem:

  1. Don't set any background color initially and use the setBGColor() method in your init() function.
  2. Generate your CSS so that in Netscape it only writes the layer-background-color property, and in IE it only writes the background-color property.
  3. Generate the entire layer on the fly and set the color then [I will be posting a lesson on how to do this very shortly]

View dynlayer-bgcolor1.html for an example illustrating this problem.

The Dynamic Layer Object

Home Next Lesson: Geometric Objects
copyright 1998 Dan Steinman