in this link https://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_widget_form_alter/7
it describes that we can add css class to an element in a form via this code
function hook_field_widget_form_alter(&$element, &$form_state, $context) { // Add a css class to widget form elements for all fields of type mytype. if ($context['field']['type'] == 'mytype') { // Be sure not to overwrite existing attributes. $element['#attributes']['class'][] = 'myclass'; } }
I tried to use it but it seems $element['#attributes']['class'][] = 'myclass';
doesn’t add any css class to form after rendering.
So how can I add css class to a form element inside hook_field_widget_form_alter()
?