How can I add the option elements a class?

Goal:

<select>
  <option class="green">Yes</option>
  <option class="red">No</option>
</select>

This code add a class to the select element:

function test_form() {
  $form['test_form'] = array(
    '#type' => 'select',
    '#default_value' => variable_get('test_form', 0),
    '#options' => array(
      'yes' => t('Yes'),
      'no' => t('No'),
    ),
   '#attributes' => array('class' => 'orange'),
}

Like http://drupal.org/node/229212 but for

Comments

krishnarp’s picture

patrickharris’s picture

'#attributes' => array('class' => 'form-autocomplete'),
Try adding that to your form.