ajax_command_invoke addClass changes lost after form validation I am currently trying to build a form which has a series of select elements, each of which triggers display of a textarea specific to that select element which is initially hidden.

Currently the select element has a callback to a function which is using ajax_command_css (to toggle the view of the textbox) and also ajax_command_invoke to add a class to the textbox so that it is still shown after validation errors are triggered. Currently after a validation event, the classes added using this method are lost so the textboxes remain hidden.

Select and textareas are created like this:

$form['2og_select'] = array(
    '#prefix' =&gt; $blurb,
    '#title' =&gt; t('2OG'),
    '#type' =&gt; 'select',
    '#options' =&gt; array(
      t(' '),t('1'),t('2'),t('3'),t('4'),t('5'),
    ),
    '#ajax' =&gt; array(
      'callback' =&gt; 'show_comments_js',
      'event' =&gt; 'change',
      'effect' =&gt; 'fade',
      'progress' =&gt; array(
        'message' =&gt; '',
        'type' =&gt; 'throbber',
      ),
    ),
  );
  $form['2og_textarea'] = array(
    '#type' =&gt; 'textfield',
    '#maxlength' =&gt; 512,
    '#suffix' =&gt; ('&lt;div style="clear:both;"&gt;&lt;/div&gt;'),
    '#attributes' =&gt; array(
      'class' =&gt; array('comments'),
    ),
  );


Callback function looks like this:

function show_comments_js($form, &amp;$form_state) {

  $commands = array();

  $triggerName = $form_state['triggering_element']['#name'];
  $triggerValue = $form_state['triggering_element']['#value'];

  $name_bits = explode('_',$triggerName);
  if ($triggerValue != '0') {
    $commands[] = ajax_command_css('#edit-' . $name_bits[0]  . '-textarea', array('display' =&gt; 'inline'));
    $commands[] = ajax_command_invoke('#edit-' . $name_bits[0]  . '-textarea', addClass, array('show-comments'));
  }
  else {
    $commands[] = ajax_command_css('#edit-' . $name_bits[0]  . '-textarea', array('display' =&gt; 'none'));
    $commands[] = ajax_command_invoke('#edit-' . $name_bits[0]  . '-textarea', removeClass, array('show-comments'));
  }

  return array('#type' =&gt; 'ajax', '#commands' =&gt; $commands);
}


I have also noticed that the id of the form has '--2' appended to it after submitting, could this be related?

Would using an ajax validation tied to the submit button have the same effect?
Yes, the IDs of an element change when it's being reloaded using AJAX. That's supposed to be a feature. :/ You might try using a class to target your textareas instead.