The prependTo method
The prependTo method adds text to the beginning of an element. There is also a prepend method that works in a similar way.
Syntax
Insert text at the beginning of an element:
$(text).prependTo(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 at the beginning of the given paragraph:
<p id="test">paragraph indent indention indentation indenture rubric</p>
$('<b>!!!</b>').prependTo('#test');
Result of code execution:
<p id="test"><b>!!!</b>paragraph indent indention indentation indenture rubric</p>
See also
-
method
prepend,
which adds text to the beginning of an element -
methods
appendTo,insertBefore⁅/ c⁆, ⁅c href="/en/javascript/lib/jquery/manual/insertAfter/"⁆insertAfter,
allowing you to add content to a specific location -
pseudo-element
before,
which adds text to the end of an element using CSS