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
 
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';
 
M

mike

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

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top