Help - Search - Members - Calendar
Full Version: changing border color
HTMLHelp Forums > Programming > Client-side Scripting
joecosmo
I have built a control to change color dynamically.
var color;// a 4 digit hex value
function setTabLColor(){
var clr = document.getElementById("mytr");
var str = color.toString(16);
clr.style.borderColor = str;// Invalid property value
clr.style.borderColor = "#" + str;;// Invalid property value
clr.style.borderColor = "#ffee00";//or ANY explicit value WORKS like "Blue"
clr.style = "border:solid 10px #" + str;// no effect
}
I am using IE 8. Have not tried this code in Opera or any other browser.
Have tried MANY other code variations including currentStyle attributes
Anybody tried this??
Christian J
QUOTE(joecosmo @ Nov 5 2009, 01:21 AM) *

var color;// a 4 digit hex value

Shouldn't there be 6 digits?

QUOTE
var str = color.toString(16);

I don't think you need that part, unless you want to convert the value of "color" to hexadecimal base.

QUOTE
clr.style.borderColor = "#" + str;;// Invalid property value

That should work if the value of "str" is valid, but only if the element already has a borderStyle property (you can set "border-style" or "border" shorthand with CSS too).

QUOTE
clr.style.borderColor = "#ffee00";//or ANY explicit value WORKS like "Blue"

Again that should only work if the element already has a borderStyle property.

QUOTE
clr.style = "border:solid 10px #" + str;// no effect

The "border" property shouldn't be part of the value. This should work (if "str" is valid):

CODE
clr.style.border="solid 10px #" + str;
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.