.prependTo(target) inserts every matched element as the first child of the target (since jQuery 1.0). Content comes first; the target is the argument — the reverse of .prepend().
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("span").prependTo("#foo")
// same DOM result as:
$("#foo").prepend($("span"))
$("<span> Test </span>").prependTo(".inner")
$("h2").prependTo($(".container"))
// first child inside target — not a sibling
// (bottom insert = .appendTo)
Call
What it does
prependTo()
Learn jQuery .prependTo(): insert matched elements as the first child of a target, content-first twin of prepend, move vs clone, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Create or select the content (HTML string, existing nodes, or a jQuery object).
Step 2
Choose the target: selector, element, HTML string, array, or jQuery object.
Step 3
Call .prependTo(target) — content becomes the first child inside.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Official Demo: Spans Into #foo
Move every <span> so it becomes the first child of #foo.
jQuery
// <div id="foo">FOO!</div>
// <span>I have something to say... </span>
$("span").prependTo("#foo");
// same as: $("#foo").prepend($("span"));
Select the heading.$("h2") already exists in the page.
One container. A single target means move, not clone.
First child. The h2 becomes the first child inside .container.
Frequently Asked Questions
.prependTo(target) inserts every matched element as the first child of the target. The target can be a selector, DOM element, HTML string, array, or jQuery object. It returns the inserted set. Available since jQuery 1.0.
Same DOM result, reversed syntax. Container first: $('#feed').prepend('<li>'). Content first: $('<li>').prependTo('#feed'). Prefer prependTo when you build the content first, then choose the container.
.prependTo() inserts as the first child (top). .appendTo() inserts as the last child (bottom). Both use content-first syntax.
One target: existing nodes move (not clone). Multiple targets: clones for every target except the last — the original moves to the final target.
No. Unlike .prepend(), which accepts a callback since 1.4, .prependTo() only takes a target. Build dynamic content first — for example $('<li>').text(msg).prependTo('#feed').
Store detached nodes with .detach(), then stash.prependTo('#container') to put them back at the top. Events and .data() survive because detach keeps jQuery state.