I have a selectlist with selectoption styled individually. I want to show the background color of selectlist same as the first child option on page-load. I've this code which is not working on pageload but onchange it is working :
<apex:selectList id="theSelectList" value="{!s}" multiselect="false" size="1" onchange="this.className=this.options[this.selectedIndex].className" >
<Script>
jQuery('[id$=theSelectList]').addClass(this.options[this.selectedIndex].className);
</Script>
<apex:selectOptions value="{!Matrix}"/>
</apex:selectlist>
Each selectoption is using HTML style as:
SelectOption entry = new SelectOption(p.id,'<option value="' + p.name + '"class="' + ColorMap.get(p.Icon_Name_vod__c) + '">' + p.name + '</option>');