faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 12 people (75%) answered Yes
Recently 4 of 7 people (57%) answered Yes

Entry

How do I have multi color options in the same select list ? I know how in IE, but no clue with NN

Nov 26th, 2004 11:54
Michael Schuster, Knowledge Based,


Just set a style-attribute to every option you want to color. If you
have this:
<select size="1">
	<option>Option 0</option>
	<option>Option 1</option>
	<option>Option 2</option>
</select>
Change it to this:
<select size="1">
	<option style="background-color:green">Option 0</option>
	<option style="background-color:grey">Option 1</option>
	<option style="background-color:lightsteelblue">Option 2</option>
</select>
If you want to do this with JS, do the following:
document.getElementsByTagName('select')[0].childNodes[0].style.setProperty('background-color','green',
null)
If you use "setAttribute('style','background-color:green')", you may get
many bugs in some browsers(see
http://www.quirksmode.org/dom/w3c_core.html#link7 for more details).
I hope I could help.