Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i change color of single element in drop down box

Status
Not open for further replies.

kuha

Technical User
Oct 23, 2001
14
US
Hi Friends,
my drop down box is having 10 element,and i want to change color of one element depending on the condition dynamically.
How can i do this, when i used
document.form.dropdown.style.color="#fffff";
it changed the color of all the element. I want only one element in dropdown box to change the color.
Thanks for all the help.
Harish
 
You need to set an ID for each option such as:
<SELECT id=select1 name=select1>
<OPTION id=&quot;opt1&quot;>One</OPTION>
<OPTION id=&quot;opt2&quot;>Two</OPTION>
<OPTION id=&quot;opt3&quot;>Three</OPTION>
<OPTION id=&quot;opt4&quot;>Four</OPTION>
</SELECT>
Then when you want to change the color you do so by the ID such as:

document.getElementById(layerName).style.backgroundColor = &quot;green&quot;;
 
Thanks Mithril, it worked.
Harish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top