Dynamically create Javascript object and give class
        Posted  
        
            by George
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by George
        
        
        
        Published on 2010-05-14T14:34:54Z
        Indexed on 
            2010/05/14
            14:44 UTC
        
        
        Read the original article
        Hit count: 195
        
JavaScript
|css
I'm dynamically creating option elements for a drop down menu using Javascript and would like to know how to add a class to them so that I can style them with CSS.
I have the following code:
for (var i=0;i<portfolio.length-1;i++) {
    portfolioSelect.options[portfolioSelect.options.length] =
        new Option(portfolio[i]);
}
where portfolio is an array populated by an outside source.
HTML where options inserted:
<select id="portfolio" name="portfolio">
    <option selected="selected" value="Select One">Select One</option>
</select>
© Stack Overflow or respective owner