18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ajax_command_prepend<br />

To add content at the beginning of an element use the prepend command.<br />

This utilizes jQuery.prepend() to add the content. The arguments for<br />

ajax_command_prepend() are $selector, $content, and $settings.<br />

Chapter 10<br />

ajax_command_remove<br />

The remove command removes elements from a page. The single argument is the<br />

selector to be removed. jQuery.remove() is utilized to remove the elements from<br />

the page.<br />

ajax_command_replace<br />

The ajax_command_html replaces the html content within an element. For cases<br />

where the entire element needs to be replaced ajax_command_replace() should be<br />

used. It takes advantage of jQuery.replaceWith() to replace the entire element.<br />

The three arguments are $selector, $html, and $settings. $html is the full html<br />

the selector will be replaced with. For example, take the html:<br />

<br />

Hello World!<br />

<br />

An ajax_command_replace() looks like the following:<br />

$commands[] = ajax_command_replace('.inner', 'Goodbye World!<br />

';<br />

This will update the html to look like the following:<br />

<br />

Goodbye World!<br />

<br />

ajax_command_restripe<br />

The restripe command tells <strong>Drupal</strong> to restripe a table. This is useful when content<br />

inside the table has been altered. The only argument is the jQuery selector for<br />

the table.<br />

[ 311 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!