jQuery .append() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DOM

Definition

.append(content) inserts content as the last child of each matched element (since jQuery 1.0). Use .prepend() for the first child.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#list").append("<li>New</li>")   // container first
$("<li>New</li>").appendTo("#list")   // content first (same result)

$("p").append(" Hello ")              // HTML / text
$("p").append(document.createTextNode("Hi"))
$(".box").append($("#widget"))        // move existing node
CallWhat it does
Matched setContainer(s) that receive content
contentHTML, Element, Text, Array, or jQuery (*or callback)
Callback (1.4+)function(index, html) → content to insert
ReturnSame jQuery collection (chainable)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
14+Used in Callback (1.4+). function(index, html) → content to insert

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Append an HTML String

Add text as the last child of every paragraph.

jQuery
$("p").append(" Hello ");
Try It Yourself

How It Works

  1. Select. $("p") matches every paragraph.
  2. Parse. jQuery turns " Hello " into content (a text node here).
  3. Insert. That content becomes the last child of each <p>.

Example 2 — Append a Text Node

Insert plain text without HTML parsing.

jQuery
$("p").append(document.createTextNode("Hello"));
Try It Yourself

How It Works

  1. Create. createTextNode("Hello") builds a real text node.
  2. Append. jQuery inserts that node as the last child.
  3. No parse. Angle brackets in the string stay literal text.

Example 3 — Move an Existing Element

Append a jQuery object — with one target, the node moves.

jQuery
$("p").append($("strong"));
// <strong> leaves its old parent and lands inside <p>
Try It Yourself

How It Works

  1. Select content. $("strong") points at an existing node.
  2. One target. jQuery detaches it and inserts it as the last child.
  3. Many targets. Clones fill every match except the last.

Frequently Asked Questions

.append() inserts content as the last child of each matched element. It accepts HTML strings, DOM elements, text nodes, arrays, jQuery objects, or a callback (since 1.4). Returns the same jQuery collection for chaining. Available since jQuery 1.0.
Same job, reversed syntax. With .append(), the container comes first: $('#list').append('<li>'). With .appendTo(), the content comes first: $('<li>').appendTo('#list').
.append() inserts as the last child. .prepend() inserts as the first child. Use append for bottom-of-list adds; use prepend for newest-first feeds.
With one target, jQuery moves the element. With multiple targets, it clones for every target except the last — the original moves to the final target.
Yes. Pass several HTML strings, DOM nodes, or jQuery objects: $('body').append($div1, newdiv2, existingEl). They insert in order as last children.
Since jQuery 1.4, yes. .append(function(index, html)) runs once per matched element. Return the content to insert. Inside the function, this is the current DOM element.
Do not append untrusted HTML strings — script tags and event attributes can run (XSS). Prefer .text() for plain text, or escape/sanitize HTML before inserting.

Next: .empty() Method

Insert matched elements into a target with reversed, content-first syntax.

.empty() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful