Index: includes/ajax.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/ajax.inc,v
retrieving revision 1.37
diff -u -p -r1.37 ajax.inc
--- includes/ajax.inc	21 Oct 2010 19:31:39 -0000	1.37
+++ includes/ajax.inc	6 Nov 2010 22:28:47 -0000
@@ -1002,7 +1002,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
@@ -1088,6 +1088,37 @@ function ajax_command_data($selector, $n
 }
 
 /**
+ * Creates a Drupal AJAX 'invoke' command.
+ *
+ * The 'invoke' command will instruct the client to 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 $arguments
+ *   (optional) A list of arguments to the jQuery $method, if any.
+ *
+ * @return
+ *   An array suitable for use with the ajax_render() function.
+ */
+function ajax_command_invoke($selector, $method, array $arguments = array()) {
+  return array(
+    'command' => 'invoke',
+    'selector' => $selector,
+    'method' => $method,
+    'arguments' => $arguments,
+  );
+}
+
+/**
  * 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.27
diff -u -p -r1.27 ajax.js
--- misc/ajax.js	25 Oct 2010 00:23:47 -0000	1.27
+++ misc/ajax.js	6 Nov 2010 22:35:11 -0000
@@ -487,6 +487,14 @@ Drupal.ajax.prototype.commands = {
   },
 
   /**
+   * Command to apply a jQuery method.
+   */
+  invoke: function (ajax, response, status) {
+    var $element = $(response.selector);
+    $element[response.method].apply($element, response['arguments']);
+  },
+
+  /**
    * 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.20
diff -u -p -r1.20 ajax.test
--- modules/simpletest/tests/ajax.test	21 Oct 2010 19:31:39 -0000	1.20
+++ modules/simpletest/tests/ajax.test	6 Nov 2010 20:34:52 -0000
@@ -211,6 +211,15 @@ class AJAXCommandsTestCase extends AJAXT
     );
     $this->assertCommand($commands, $expected, "'data' AJAX command issued with correct key and value");
 
+    // Tests the 'invoke' command.
+    $commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX invoke command: Invoke addClass() method.")));
+    $expected = array(
+      'command' => 'invoke',
+      'method' => 'addClass',
+      'argument' => 'error',
+    );
+    $this->assertCommand($commands, $expected, "'invoke' AJAX command issued with correct method and argument");
+
     // Tests the 'html' command.
     $commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX html: Replace the HTML in a selector.")));
     $expected = array(
Index: modules/simpletest/tests/ajax_forms_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/ajax_forms_test.module,v
retrieving revision 1.8
diff -u -p -r1.8 ajax_forms_test.module
--- modules/simpletest/tests/ajax_forms_test.module	4 Oct 2010 17:46:01 -0000	1.8
+++ modules/simpletest/tests/ajax_forms_test.module	6 Nov 2010 21:57:16 -0000
@@ -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."),
@@ -332,6 +342,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', array('error'));
+  return array('#type' => 'ajax', '#commands' => $commands);
+}
+
+/**
  * AJAX callback for 'html'.
  */
 function ajax_forms_test_advanced_commands_html_callback($form, $form_state) {
