The insertBefore method
The insertBefore method adds text before the given element. There is also a before method that works in a similar way.
Syntax
Insert text before an element:
$(text).insertBefore(selector);
The content can be not only plain text, but also a DOM element, selector, array of elements, string or jQuery object.
Example
Let's insert text with tags before the given paragraph:
<p id="test">paragraph indent indention indentation indenture rubric</p>
$('<p>!!!</p>').insertBefore('#test');
HTML the code will look like this:
<p>!!!</p><p id="test">paragraph indent indention indentation indenture rubric</p>
See also
-
method
before,
which adds text before the given element -
methods
insertAfter,appendTo⁅/ c⁆, ⁅c href="/en/javascript/lib/jquery/manual/prependTo/"⁆prependTo,
allowing you to add content to a specific location on a page -
method
clone,
which creates copies of the selected elements