The .append() method inserts content as the last child inside each matched element. This tutorial covers HTML strings, text nodes, DOM elements, jQuery objects, multiple arguments, and the callback form since 1.4, comparisons with .appendTo(), .prepend(), and .html(), the official jQuery demos, and five practical try-it examples.
01
.append()
Last child
02
HTML
Strings
03
DOM
Move nodes
04
Callback
Since 1.4
05
vs prepend
First child
06
Since 1.0
Core API
Fundamentals
Introduction
Dynamic pages constantly add new content — append a message to a chat log, insert a table row after a form submit, or drop a widget into a dashboard panel. When new nodes should appear at the bottom inside a container, jQuery provides .append().
Available since jQuery 1.0, .append() inserts the specified content as the last child of each matched element. You can pass an HTML string, a text node, a DOM element, a jQuery object, an array of nodes, multiple arguments, or a callback function that returns content (since 1.4).
.append() and .appendTo() perform the same task with reversed syntax — the selector before .append() is the container. Use .prepend() to insert at the top instead. Pair with .empty() before appending when replacing container contents. Browse the jQuery DOM hub for related manipulation methods.
Concept
Understanding the .append() Method
.append( content [, content ] ) adds content inside each matched element, after any existing children. The return value is the same jQuery collection (for chaining). When you append an element already in the document to a single target, jQuery moves it rather than copying it.
Since jQuery 1.4, the callback form .append( function( index, html ) ) runs once per matched element. Return an HTML string, DOM node, or jQuery object to insert. Inside the callback, this refers to the current DOM element.
💡
Beginner Tip
$(".inner").append(" Test ") adds the text “ Test ” as the last child of every .inner element — the official jQuery demo appends to all matching paragraphs at once.
Foundation
📝 Syntax
jQuery .append() supports three forms:
Append content — since 1.0
jQuery
.append( content [, content ] )
content — HTML string, DOM element, text node, array, or jQuery object.
Multiple arguments are inserted in order as last children.
Append with callback — since 1.4
jQuery
.append( function( index, html ) {
// return content to insert; `this` is the current element
} )
index — zero-based position in the matched set.
html — current inner HTML of the element.
Return value
Returns the same jQuery collection that received the appended content.
📋 .append() vs .appendTo() vs .prepend() vs .html()
Four related content-insertion APIs — pick the right insertion strategy.
.append()
last child
Insert content at the end inside matched elements — container comes first in syntax
.appendTo()
same task
Insert content at the end — content comes first: $(el).appendTo(target)
.prepend()
first child
Insert content at the beginning inside matched elements
.html()
replace
Set inner HTML as a string — replaces all existing children
Hands-On
Examples Gallery
Examples 1–5 follow the official jQuery API documentation and common production patterns. Use DevTools or the Try-it links to run each snippet in the browser.
📚 Getting Started
Official jQuery demos for HTML strings, text nodes, and existing elements.
Example 1 — Official Demo: Append HTML String
Append the text “ Hello ” as the last child of every paragraph.
Before: <p>I would like to say:</p>
After: <p>I would like to say: Hello </p>
Content added as last child — existing text preserved
How It Works
jQuery parses the string and inserts it at the end of each matched element’s contents. Plain text is appended as a text node. Avoid passing untrusted HTML strings to prevent XSS vulnerabilities.
Example 2 — Official Demo: Append a Text Node
Insert plain text using document.createTextNode() instead of an HTML string.
Text node "Hello" appended — no HTML parsing
Safer for user-supplied plain text (still escape if needed)
Same visual result as append("Hello") for simple text
How It Works
Text nodes bypass HTML parsing entirely, so no tags are interpreted. This is a safer approach when inserting user-provided plain text that must not contain markup.
📈 Practical Patterns
Moving elements, callback insertion, and dynamic list building.
Example 3 — Official Demo: Append a jQuery Object (Move Element)
Append an existing <strong> element into paragraphs — jQuery moves it from its original location.
jQuery
$( "p" ).append( $( "strong" ) );
// <strong>Hello world!!!</strong> moves into each <p>
// (cloned for all but last target if multiple matches)
<strong> removed from original location
Appended as last child of matched <p> elements
Single target → element moves (not cloned)
How It Works
When appending an existing DOM node to one target, jQuery detaches it from its old parent and inserts it at the new location. With multiple targets, clones are created for all but the last match.
Example 4 — Append With Callback Function
Generate unique appended content per element using the callback form (since 1.4).
Each .item gets a unique #1, #2, #3 badge appended
Callback runs once per matched element
`this` inside callback refers to the current DOM element
How It Works
The callback receives the element’s index in the set and its current inner HTML. Return a string, DOM node, or jQuery object to append. Useful for numbered labels or per-item suffixes without manual loops.
Example 5 — Build a List From an Array
Empty a container, then append list items built from JavaScript data.
jQuery
var fruits = [ "Apple", "Banana", "Cherry" ];
var $list = $( "#fruits" ).empty();
fruits.forEach(function( name ) {
$list.append( $( "<li>" ).text( name ) );
});
#fruits emptied, then three <li> elements appended
Using .text() on created elements avoids XSS from data
Common pattern with Ajax JSON responses
How It Works
Creating elements with $("<li>").text(name) and appending them is safer than concatenating HTML strings from server data. Pair .empty() with .append() for idempotent list rendering.
Applications
🚀 Common Use Cases
Chat logs — append new messages to the bottom of a conversation panel.
Todo lists — append a new <li> when the user adds an item.
Table rows — append <tr> elements to tbody after Ajax loads data.
Dashboard widgets — move an existing panel into a layout container with append.
Form fields — append cloned input groups to a dynamic form section.
Reinsert detached nodes — stash.appendTo("#container") after .detach().
🧠 How .append() Inserts Content
1
Match container elements
jQuery collection points at parent nodes that will receive content.
Select
2
Parse or accept content
HTML strings are parsed; DOM nodes and jQuery objects are inserted directly.
Content
3
Insert as last child
Content is added after all existing children inside each matched element.
Append
4
➕
Return jQuery collection
Same container collection — ready for chaining or event binding.
Important
📝 Notes
Available since jQuery 1.0 — callback form added in jQuery 1.4.
Inserts as the last child; use .prepend() for the first child.
Appending an existing element to one target moves it; multiple targets clone except the last.
Multiple arguments are supported: .append(a, b, c).
Do not append HTML strings from untrusted user input — XSS risk via script tags or event attributes.
Prefer .text() on created elements over string concatenation for dynamic data.
.append() adds content; .html() replaces all inner content.
Compatibility
Browser Support
.append() has been part of jQuery since 1.0+, with the callback form since 1.4+. It relies on standard DOM appendChild operations. Works in all browsers supported by your jQuery build — IE6+ through modern evergreen browsers in legacy jQuery versions, and all current browsers in jQuery 3.x and 4.x.
✓ jQuery 1.0+
jQuery .append()
Universal DOM insertion API across jQuery 1.x, 2.x, 3.x, and 4.x. No browser-specific polyfills required — jQuery normalizes content insertion. Pair with .empty() for container refresh patterns.
100%With jQuery loaded
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
.append()Universal
Bottom line: Default choice for adding content as the last child inside matched elements.
Wrap Up
Conclusion
The jQuery .append() method inserts content as the last child inside each matched element. Pass HTML strings, text nodes, DOM elements, jQuery objects, multiple arguments, or a callback function — exactly as the official jQuery demos demonstrate.
Use .prepend() for first-child insertion and .appendTo() when reversed syntax reads better. Next up: inserting with content-first syntax using .appendTo().
Confuse .append() with .prepend() (last vs first child)
Append without emptying first when re-rendering lists (duplicates stack up)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .append()
The add-at-the-bottom API — last child insertion made easy.
5
Core concepts
+01
Last
Child
Insert
<>02
HTML
Or DOM
Content
→03
Move
Not clone
Single
fn04
Callback
Since 1.4
Dynamic
≠05
vs prepend
First child
Compare
❓ Frequently Asked Questions
.append() inserts the specified content as the last child of each element in the matched set. It accepts HTML strings, DOM elements, text nodes, arrays, jQuery objects, or a callback function (since 1.4). Returns the same jQuery collection for chaining. Available since jQuery 1.0.
Both insert content at the end of target elements. With .append(), the selector before the method is the container: $('#list').append('<li>'). With .appendTo(), the content comes first: $('<li>').appendTo('#list'). Same result, reversed syntax.
.append() inserts content as the last child inside each matched element. .prepend() inserts as the first child. Use append to add items to the bottom of a list; use prepend for newest-first feeds.
When you append an existing DOM element to a single target, jQuery moves it (not clones). If you append to multiple targets, jQuery clones the element for every target except the last — the original moves to the final target.
Yes. Pass multiple DOM elements, HTML strings, or jQuery objects: $('body').append($div1, newdiv2, existingEl). jQuery inserts each argument in order as the last children.
Since jQuery 1.4, yes. .append(function(index, html)) runs once per matched element. The callback receives the index and old inner HTML; return content to insert. Inside the function, this refers to the current DOM element.
Did you know?
.append() has been in jQuery since version 1.0 — one of the original DOM manipulation methods. Its mirror method .appendTo() uses reversed syntax but performs identical insertion. When jQuery 1.4 added the callback form, it joined .html() and .text() in supporting function arguments for per-element content generation. Under the hood, appending an existing node uses the same move-or-clone logic that makes .detach() and .appendTo() work together as a stash-and-restore pair.