function ajax_command_prepend

Creates a Drupal Ajax 'insert/prepend' command.

The 'insert/prepend' command instructs the client to use jQuery's prepend() method to prepend the given HTML content to the inside each element matched by the given selector.

This command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js.


$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.

$html: The data to use with the jQuery prepend() method.

$settings: An optional array of settings that will be used for this command only.

Return value

An array suitable for use with the ajax_render() function.

See also

Related topics

4 calls to ajax_command_prepend()
ajax_forms_test_advanced_commands_prepend_callback in drupal/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
Ajax form callback: Selects 'prepend'.
ajax_prepare_response in drupal/core/includes/
Converts the return value of a page callback into an Ajax commands array.
ajax_render in drupal/core/includes/
Renders a commands array into JSON.
hook_ajax_render_alter in drupal/core/modules/system/system.api.php
Alter the commands that are sent to the user through the Ajax framework.


drupal/core/includes/, line 832
Functions for use with Drupal's Ajax framework.


function ajax_command_prepend($selector, $html, $settings = NULL) {
  return array(
    'command' => 'insert',
    'method' => 'prepend',
    'selector' => $selector,
    'data' => $html,
    'settings' => $settings,