Inserts HTML at the specified position relative to the DOM element identified by the given id.
position may be one of:
| :top: | HTML is inserted inside the element, before the element’s existing content. |
| :bottom: | HTML is inserted inside the element, after the element’s existing content. |
| :before: | HTML is inserted immediately preceding the element. |
| :after: | HTML is inserted immediately following the element. |
options_for_render may be either a string of HTML to insert, or a hash of options to be passed to ActionView::Base#render. For example:
# Insert the rendered 'navigation' partial just before the DOM # element with ID 'content'. # Generates: new Insertion.Before("content", "-- Contents of 'navigation' partial --"); insert_html :before, 'content', :partial => 'navigation' # Add a list item to the bottom of the <ul> with ID 'list'. # Generates: new Insertion.Bottom("list", "<li>Last item</li>"); insert_html :bottom, 'list', '<li>Last item</li>'</ul>
Source Code
# File action_view/helpers/prototype_helper.rb, line 725 def insert_html(position, id, *options_for_render) insertion = position.to_s.camelize call "new Insertion.#{insertion}", id, render(*options_for_render) end
<code/>and<pre/>for code samples.