The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> changing border color, using a variable
joecosmo
post Nov 4 2009, 07:21 PM
Post #1





Group: Members
Posts: 1
Joined: 4-November 09
Member No.: 10,239



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??
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Nov 5 2009, 06:21 AM
Post #2


¤¤¤¤¤¤¤¤¤
********

Group: WDG Moderators
Posts: 2,371
Joined: 10-August 06
Member No.: 7



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;
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 21st November 2009 - 10:59 AM