Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q1759 How can I create an option in a select statement with a particular style?

You are here: irt.org | FAQ | JavaScript | Form | 1 | Q1759 [ previous next ]

If you have a SELECT statement named "myselect" using the following

var opt = new Option('text of option','value of option');
opt.style.color = 'red';
myselect.options[1] = opt;

it will create an option, subscript 1, coloured red.

However, if you want to change the font attributes you have to do this on the select statement itself:

myselect.style.fontFamily = 'Courier';

Note that the style names in CSS are converted to camelCase, thus font-family becomes fontFamily.

©2018 Martin Webb