class method Element.insert
Element.insert(element, content) → Element
Inserts content above, below, at the top, and/or at the bottom of the
given element, depending on the option(s) given.
insert accepts content in any of these forms:
String: A string of HTML to be parsed and renderedElement: An Element instance to insert- ...any object with a
toElementmethod: The method is called and the resulting element used - ...any object with a
toHTMLmethod: The method is called and the resulting HTML string is parsed and rendered
The content argument can be the content to insert, in which case the implied
insertion point is bottom, or an object that specifies one or more insertion
points (e.g., { bottom: "foo", top: "bar" }).
Accepted insertion points are:
before(aselement's previous sibling)after(aselement'snext sibling)top(aselement's first child)bottom(aselement's last child)
Examples
Insert the given HTML at the bottom of the element (using the default):
$('myelement').insert("<p>HTML to append</p>");
$('myelement').insert({
top: new Element('img', {src: 'logo.png'})
});
Put hrs before and after the element:
$('myelement').insert({
before: "<hr>",
after: "<hr>"
});
This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.