create and change the color of the option


M

mike

I am trying to change the style for an option in a select after it gets
created.

here is my code for creating the option:

function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
theSel.options[selLength].style = "color:#ff0000";
}

I get an error on the style line.

Anyone know how I can change the color of the option?

Mike
 
Ad

Advertisements

J

Jedi Fans

mike said:
I am trying to change the style for an option in a select after it gets
created.

here is my code for creating the option:

function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
theSel.options[selLength].style = "color:#ff0000";
}

I get an error on the style line.

Anyone know how I can change the color of the option?

Mike
not sure if all browsers allow option elements to be coloured but at any
rate:

theSel.options[selLength].style = "color:#ff0000";
should be:
theSel.options[selLength].style.color='#ff0000';
 
Ad

Advertisements

M

mike

thanks, that works ... this particular page is an IE only page, so it
works fine.

Mike
 

Top