Select the container, pass content (or a callback), insert at the top.
Select the parent element(s) with jQuery.
Pass HTML, a DOM node, text node, array, or jQuery object.
Or pass a function (since 1.4) that returns content per element.
Chain further on the same collection — prepend returns the originals.
Piece
Required?
Role
jQuery collection
Yes
Container(s) to insert into
content / function
Yes
What goes in as the first child
Return
—
Same matched set (chainable)
Pseudocode
Pseudocode
for each container in matched set:
place content as first child inside container
if content is an existing node and many containers:
clone for all but the last container
move original into the last container
// Official idea:
$(".inner").prepend("<span> Test </span>")
$(".container").prepend($("h2")) // move, not clone (one target)
// Reversed twin:
content.prependTo(target) ≡ target.prepend(content)
Reference
Cheat Sheet
Keep these facts handy while inserting at the top.
Topic
Detail
Syntax
.prepend(content) / .prepend(fn)
Since
1.0 (callback since 1.4)
Position
First child inside the target
vs .append()
Top vs bottom inside
vs .prependTo()
Container-first vs content-first
One target
Existing nodes move
Many targets
Clones except for the last
Try it
Live Preview
Run official-style prepend actions on a tiny demo tree and see the first-child order change.
Browser demo of .prepend() — 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: Prepend HTML
Insert a bold greeting as the first child of every paragraph.
Check these before using .prepend() in real pages.
inside
Child, not sibling
prepend goes inside. For a sibling above the element, use .before().
move
One target moves nodes
Existing elements leave their old spot. Multiple targets clone except for the last.
xss
Untrusted HTML is unsafe
Prefer .text() for user strings, or sanitize before prepending markup.
syntax
Container first
$("#feed").prepend(html). Content-first style is .prependTo().
Compatibility
Browser Support
.prepend() is a core jQuery method (since 1.0; callback since 1.4). It needs a browser DOM with jQuery loaded.
✓ jQuery 1.0+ · Browsers only
jQuery .prepend()
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
.prepend()Browsers
Bottom line: Use .prepend(content) in the browser to insert as the first child. Prefer .text() for untrusted strings.
Analysis
Performance Notes
Approach
Cost
Best for
.prepend(html)
Low
Single inserts / small feeds
.prepend many times in a loop
Higher
Avoid — batch or build a fragment first
Native Element.prepend
Lowest
Hot paths without jQuery
Prefer one clear prepend over many tiny DOM writes in a tight loop. Build markup once when inserting several siblings at the top.
Remember
Key Takeaways
Role: insert content as the first child inside matched elements.
vs append: top vs bottom inside the same parent.
Twin:.prependTo() is content-first syntax.
Move vs clone: one target moves; many targets clone.
One line:$(target).prepend(content) puts new nodes at the top inside the target — the opposite of .append().
Frequently Asked Questions
.prepend() inserts content as the first child of each matched element. It accepts HTML strings, DOM elements, text nodes, arrays, jQuery objects, multiple arguments, or a callback (since 1.4). Returns the same jQuery collection for chaining. Available since jQuery 1.0.
.prepend() inserts as the first child (top). .append() inserts as the last child (bottom). Use prepend for newest-first feeds; use append for lists that grow downward.
Same DOM result, reversed syntax. Container first: $('#feed').prepend('<li>'). Content first: $('<li>').prependTo('#feed'). Prefer prepend when the container is already selected.
One target: existing nodes move (not clone). Multiple targets: clones for every target except the last — the original moves to the final target.
Yes, since jQuery 1.4. .prepend(function(index, html)) runs once per matched element. Return an HTML string, DOM node, or jQuery object. Inside the function, this is the current element.
.prepend() inserts inside the element as the first child. .before() inserts as a previous sibling outside the element.