Index: includes/ajax.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/ajax.inc,v
retrieving revision 1.31
diff -u -p -r1.31 ajax.inc
--- includes/ajax.inc	30 Apr 2010 08:07:54 -0000	1.31
+++ includes/ajax.inc	5 Aug 2010 18:08:55 -0000
@@ -848,7 +848,7 @@ function ajax_command_changed($selector,
  * The 'css' command will instruct the client to use the jQuery css() method
  * to apply the CSS arguments to elements matched by the given selector.
  *
- * This command is implemented by Drupal.ajax.prototype.commands.insert()
+ * This command is implemented by Drupal.ajax.prototype.commands.css()
  * defined in misc/ajax.js.
  *
  * @param $selector
@@ -934,6 +934,37 @@ function ajax_command_data($selector, $n
 }
 
 /**
+ * Creates a Drupal AJAX 'invoke' command.
+ *
+ * The 'invoke' command will instruct the client to use invoke the given jQuery
+ * method with the supplied argument on the elements matched by the given
+ * selector. Should be used for simple jQuery commands only, such as attr(),
+ * addClass(), removeClass(), toggleClass(), etc.
+ *
+ * This command is implemented by Drupal.ajax.prototype.commands.invoke()
+ * defined in misc/ajax.js.
+ *
+ * @param $selector
+ *   A jQuery selector string. If the command is a response to a request from
+ *   an #ajax form element then this value can be NULL.
+ * @param $method
+ *   The jQuery method to invoke.
+ * @param $argument
+ *   (optional) The argument to the jQuery $method, if any.
+ *
+ * @return
+ *   An array suitable for use with the ajax_render() function.
+ */
+function ajax_command_invoke($selector, $method, $argument = NULL) {
+  return array(
+    'command' => 'invoke',
+    'selector' => $selector,
+    'method' => $method,
+    'argument' => $argument,
+  );
+}
+
+/**
  * Creates a Drupal AJAX 'restripe' command.
  *
  * The 'restripe' command instructs the client to restripe a table. This is
Index: misc/ajax.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/ajax.js,v
retrieving revision 1.18
diff -u -p -r1.18 ajax.js
--- misc/ajax.js	25 Jun 2010 20:34:07 -0000	1.18
+++ misc/ajax.js	5 Aug 2010 18:00:58 -0000
@@ -434,6 +434,13 @@ Drupal.ajax.prototype.commands = {
   },
 
   /**
+   * Command to apply a jQuery method.
+   */
+  invoke: function (ajax, response, status) {
+    $(response.selector)[response.method](response.argument);
+  },
+
+  /**
    * Command to restripe a table.
    */
   restripe: function (ajax, response, status) {
Index: modules/simpletest/tests/ajax.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/ajax.test,v
retrieving revision 1.12
diff -u -p -r1.12 ajax.test
--- modules/simpletest/tests/ajax.test	30 Jul 2010 02:47:28 -0000	1.12
+++ modules/simpletest/tests/ajax.test	5 Aug 2010 18:08:05 -0000
@@ -132,7 +132,7 @@ class AJAXCommandsTestCase extends AJAXT
     $this->assertTrue($command['command'] == 'changed' && $command['selector'] == '#changed_div' && $command['asterisk'] == '#changed_div_mark_this', "'changed' AJAX command (with asterisk) issued with correct selector");
 
     // Tests the 'css' command.
-    $commands = $this->discardSettings($this->drupalPostAJAX($form_path, $edit, array('op' => t("Set the the '#box' div to be blue."))));
+    $commands = $this->discardSettings($this->drupalPostAJAX($form_path, $edit, array('op' => t("Set the '#box' div to be blue."))));
     $command = $commands[0];
     $this->assertTrue($command['command'] == 'css' && $command['selector'] == '#css_div' && $command['argument']['background-color'] == 'blue', "'css' AJAX command issued with correct selector");
 
@@ -141,6 +141,11 @@ class AJAXCommandsTestCase extends AJAXT
     $command = $commands[0];
     $this->assertTrue($command['command'] == 'data' && $command['name'] == 'testkey' && $command['value'] == 'testvalue', "'data' AJAX command issued with correct key and value");
 
+    // Tests the 'invoke' command.
+    $commands = $this->discardSettings($this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX invoke command: Invoke addClass() method."))));
+    $command = $commands[0];
+    $this->assertTrue($command['command'] == 'invoke' && $command['method'] == 'addClass' && $command['argument'] == 'error', "'invoke' AJAX command issued with correct method and argument");
+
     // Tests the 'html' command.
     $commands = $this->discardSettings($this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX html: Replace the HTML in a selector."))));
     $command = $commands[0];
Index: modules/simpletest/tests/ajax_forms_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/ajax_forms_test.module,v
retrieving revision 1.7
diff -u -p -r1.7 ajax_forms_test.module
--- modules/simpletest/tests/ajax_forms_test.module	6 May 2010 05:59:31 -0000	1.7
+++ modules/simpletest/tests/ajax_forms_test.module	5 Aug 2010 18:08:37 -0000
@@ -156,7 +156,7 @@ function ajax_forms_test_ajax_commands_f
 
   // Shows the AJAX 'css' command.
   $form['css_command_example'] = array(
-    '#value' => t("Set the the '#box' div to be blue."),
+    '#value' => t("Set the '#box' div to be blue."),
     '#type' => 'submit',
     '#ajax' => array(
       'callback' => 'ajax_forms_test_advanced_commands_css_callback',
@@ -176,6 +176,16 @@ function ajax_forms_test_ajax_commands_f
     '#suffix' => '<div id="data_div">Data attached to this div.</div>',
   );
 
+  // Shows the AJAX 'invoke' command.
+  $form['invoke_command_example'] = array(
+    '#value' => t("AJAX invoke command: Invoke addClass() method."),
+    '#type' => 'submit',
+    '#ajax' => array(
+      'callback' => 'ajax_forms_test_advanced_commands_invoke_callback',
+    ),
+    '#suffix' => '<div id="invoke_div">Original contents</div>',
+  );
+
   // Shows the AJAX 'html' command.
   $form['html_command_example'] = array(
     '#value' => t("AJAX html: Replace the HTML in a selector."),
@@ -323,6 +333,15 @@ function ajax_forms_test_advanced_comman
 }
 
 /**
+ * AJAX callback for 'invoke'.
+ */
+function ajax_forms_test_advanced_commands_invoke_callback($form, $form_state) {
+  $commands = array();
+  $commands[] = ajax_command_invoke('#invoke_div', 'addClass', 'error');
+  return array('#type' => 'ajax', '#commands' => $commands);
+}
+
+/**
  * AJAX callback for 'html'.
  */
 function ajax_forms_test_advanced_commands_html_callback($form, $form_state) {
