How to hide a form element having a certain class in ajax callback in form? How can I hide the product using ajax callback . I am trying to implement that using ajax_commands_invoke but it does not work using below code

  $form['field_product_type_select']['und']['#ajax']= array('callback' =&gt; '_change_table_product_type','wrapper' =&gt; 'display-table-ajaxify');
 $header = array(
   'field_name' =&gt; t('Field Name'),
   'field_type' =&gt; t('Field Type'),
   'field_no_of_values' =&gt; t('Single/Multi Value'),
 );
 $options = array();

 foreach(commerce_product_types() as $product_type =&gt; $product_type_array){
   $field_info_instances = field_info_instances('commerce_product',$product_type);

   foreach($field_info_instances as $key =&gt; $value){
   $field_info_types = field_info_field_types($value['type']);
   $options[$key] = array(
     'field_name' =&gt; $value['label'],
     'field_type' =&gt; $field_info_types['label'],
     'field_no_of_values' =&gt; $value['cardinality'],
   );
  }

 $form['display_table'][$product_type] = array(
   '#type' =&gt; 'tableselect',
   '#options' =&gt; $options,
   '#header' =&gt; $header,
   '#multiple' =&gt; TRUE,
   '#prefix' =&gt; '&lt;div class="display-'.$product_type.'" id="display-table-ajaxify" style="display:none;"&gt;&lt;b&gt;'.\
$product_type_array['name'].'&lt;/b&gt;',
   '#suffix' =&gt; '&lt;/div&gt;',
 );
 }

function _change_table_product_type(&amp;$form,&amp;$form_state){
  $commands = array();
  $product_type = $form_state['values']['field_product_type_select']['und'][0]['value'];
  drupal_set_message($product_type);
  $commands[] = ajax_command_invoke('display-'.$product_type,'show');


  /* $product_type = $form_state['values']['field_product_type_select']['und'][0]['value']; */
  /* foreach ($form['display_table'] as $key =&gt; $value){ */
  /*   if ($key != $product_type) { */
  /*     unset($form['display_table'][$key]); */
  /*   } */

  /* } */
  //  return $form['display_table'][$product_type];
  //  return array('#type' =&gt; 'ajax', '#commands' =&gt; $commands);
  print ajax_render($commands);
}
AJAX Commands are supposed to be returned in the callback function, not printed. Also, you have to give a CSS valid selector.

Try this:

function _change_table_product_type(&amp;$form,&amp;$form_state){
  $commands = array();
  $product_type = $form_state['values']['field_product_type_select']['und'][0]['value'];
  drupal_set_message($product_type);
  $commands[] = ajax_command_invoke('.display-' . $product_type, 'show');

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

}


You can show the actual selector that code generates and test it in the JavaScript console. Just type:

 jQuery('CSS_SELECTOR').show();


If element is shown your CSS selector code is right.