Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form 1 | Q1759 [ previous next ]

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

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.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.