.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().
Remember
$("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)
Build or select content, pass a target, insert as the first child.
Create or select the content (HTML string, existing nodes, or a jQuery object).
Choose the target: selector, element, HTML string, array, or jQuery object.
Call .prependTo(target) — content becomes the first child inside.
Chain further on the returned inserted set (reliable since jQuery 1.9).
Piece
Required?
Role
jQuery collection
Yes
Content to insert
target
Yes
Container that receives content first
Return
—
Inserted element set (jQuery 1.9+)
Pseudocode
Pseudocode
content = matched elements (or new HTML nodes)
targets = resolve(target)
for each t in targets:
if last target:
move content as first child of t
else:
clone content as first child of t
return inserted set
// Same idea as .prepend(), reversed syntax:
// content.prependTo(target) ≡ target.prepend(content)
Reference
Cheat Sheet
Keep these facts handy while inserting into a target.
Topic
Detail
Syntax
.prependTo(target)
Since
jQuery 1.0
Position
First child inside the target
vs .prepend()
Same result; content-first vs container-first
Callback?
No — build dynamic nodes first
One target
Existing nodes move
Many targets
Clones except for the last
Try it
Live Preview
Run official-style prependTo actions on a tiny demo tree and see content land as the first child.
Browser demo of .prependTo() — same idea as the examples below.
Result
Ready — pick an action and run.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
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.
Return value. Since 1.9 you get the inserted set for chaining.
Example 4 — prependTo vs prepend
Same first-child result; pick the syntax that matches how you think.
jQuery
// Content first — build, then place
$("<li>").text("New").prependTo("#list");
// Container first — same DOM result
$("#list").prepend($("<li>").text("New"));
Build safely..text() sets item text without HTML injection.
Content-first.prependTo reads naturally when the node is ready first.
Container-first.prepend reads naturally when the list is already selected.
Same child. Both place New as the first child of #list.
Edge Cases & Pitfalls
Check these before using .prependTo() in real pages.
inside
Child, not sibling
prependTo goes inside the target. For a sibling above, use .insertBefore().
move
One target moves nodes
Existing elements leave their old spot. Multiple targets clone except for the last.
callback
No callback form
Unlike .prepend(), build dynamic content first, then call prependTo.
xss
Untrusted HTML is unsafe
Prefer .text() for user strings. Never inject raw markup from URLs or forms.
Compatibility
Browser Support
.prependTo() is a core jQuery method (since 1.0). It needs a browser DOM with jQuery loaded. Return-value chaining for single-target inserts is solid since 1.9.
✓ jQuery 1.0+ · Browsers only
jQuery .prependTo()
Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery. Not for Node.js without a DOM.
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.prependTo()Browsers
Bottom line: Use .prependTo(target) in the browser for content-first first-child insertion. Prefer jQuery 1.9+ when chaining on the inserted set.
Analysis
Performance Notes
Approach
Cost
Best for
.prependTo(one)
Low
Single first-child insert / move
.prependTo(many)
Higher
Clones per extra target — expect more work
Native Element.prepend
Lowest
Hot paths without jQuery
Prefer one clear insert over many tiny DOM moves in a loop. Batch when you can, and avoid inserting untrusted HTML strings.
Remember
Key Takeaways
Role: insert matched content as the first child of a target.
Syntax: content first — mirror of .prepend().
vs appendTo: top vs bottom inside the target.
Move vs clone: one target moves; many targets clone.
One line:$(content).prependTo(target) puts nodes at the top inside the target — content-first twin of .prepend().
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.