The .after() method inserts content immediately after each matched element as a sibling. This tutorial covers HTML strings, text nodes, DOM elements, jQuery objects, multiple arguments, and the callback form since 1.4, comparisons with .before(), .insertAfter(), and .append(), the official jQuery demos, and five practical try-it examples.
01
.after()
Next sibling
02
HTML
Strings
03
DOM
Move nodes
04
Callback
Since 1.4
05
vs .before()
Sibling pair
06
Since 1.0
Core API
Fundamentals
Introduction
Form disclaimers, horizontal rules, helper text, and follow-up panels often need to appear right below an existing element — not inside it. When content should sit as the next sibling after a matched node, jQuery provides .after().
Available since jQuery 1.0, .after() is the mirror of .before(). Where .before() inserts content above the element, .after() inserts it below. You can pass HTML strings, text nodes, DOM elements, jQuery objects, multiple arguments, or a callback function (since 1.4).
.after() and .insertAfter() perform the same task with reversed syntax. Use .append() when content belongs inside the element. Browse the jQuery DOM hub for related manipulation methods.
Concept
Understanding the .after() Method
.after( content [, content ] ) inserts content immediately after each matched element in the DOM tree. The matched element itself is unchanged; new nodes appear as its following siblings. The return value is the same jQuery collection (for chaining).
When inserting an element already in the document after a single target, jQuery moves it rather than copying it. Since jQuery 1.4, the callback form .after( function( index ) ) runs once per matched element; return content to insert after that element.
💡
Beginner Tip
$(".inner").after(" Test ") adds “ Test ” after every .inner element — the official jQuery demo shows text appearing below “Hello” and “Goodbye”, not inside them.
Foundation
📝 Syntax
jQuery .after() supports three forms:
Insert after — since 1.0
jQuery
.after( content [, content ] )
content — HTML string, DOM element, text node, array, or jQuery object.
Multiple arguments are inserted in order after each matched element.
Insert with callback — since 1.4
jQuery
.after( function( index [, html ] ) {
// return content to insert; `this` is the current element
} )
📋 .after() vs .before() vs .insertAfter() vs .append()
Four related insertion APIs — pick the right position and syntax.
.after()
next sibling
Insert content immediately after matched elements — anchor first: $(target).after(content)
.before()
prev sibling
Insert content immediately before matched elements
.insertAfter()
same task
Insert after target — content first: $(content).insertAfter(target)
.append()
last child
Insert content inside matched elements as the last child
Hands-On
Examples Gallery
Examples 1–3 follow the official jQuery API documentation. Examples 4–5 cover the callback form and multiple-argument insertion from the docs. 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: Insert HTML After Paragraphs
Insert “ Hello ” immediately after every paragraph.
Before: <p>I would like to say:</p>
After: <p>I would like to say:</p> Hello
" Hello " appears as sibling after each <p> — not inside it
How It Works
jQuery inserts the string as the next sibling after each matched element. The paragraph content is unchanged; the new text sits outside and below the closing tag. Avoid untrusted HTML strings to prevent XSS.
Example 2 — Official Demo: Insert a Text Node After
Insert plain text with document.createTextNode() instead of an HTML string.
Text node "Hello" inserted after each paragraph
No HTML parsing — safer for plain text
Official jQuery Example 2 pattern
How It Works
Text nodes bypass HTML parsing. The text appears immediately after each paragraph as a sibling node, exactly like the HTML string version but without interpreting tags.
📈 Practical Patterns
Moving elements, callback insertion, and multiple-argument sibling insertion.
Example 3 — Official Demo: Insert a jQuery Object After
Insert an existing <b> element after paragraphs — jQuery moves it from its original location.
jQuery
$( "p" ).after( $( "b" ) );
// <b>Hello</b> moves to follow each <p>
// (cloned for all but last target if multiple matches)
<b> removed from original location
Inserted as sibling after matched <p> elements
Single target → element moves (not cloned)
How It Works
Inserting an existing DOM node after one target moves it to follow that element. With multiple targets, clones are created for all but the last match — same move-or-clone rules as .append() and .prepend().
Example 4 — Insert After With Callback Function
Generate unique content after each paragraph using the callback form (since 1.4) — official jQuery pattern.
Each <p> gets a <b> sibling showing its className
Callback runs once per matched element
<b> appears after the paragraph, not inside it
How It Works
The callback receives the index (and optionally old HTML since 1.10). Return a string, DOM node, or jQuery object to insert after the current element. Inside the function, this refers to the DOM element being processed.
Example 5 — Multiple Arguments After First Paragraph
Pass several DOM elements and HTML strings in one call — official jQuery multi-argument pattern.
Three nodes inserted after first <p> in order:
1. jQuery div.note
2. createElement div
3. existing #foo element (moved)
Equivalent to .after(a, b, c) with separate arguments
How It Works
jQuery accepts arrays of nodes alongside individual arguments. Each item is inserted in order after the first paragraph. Existing elements move to the new location; newly created nodes are appended as siblings. Useful for inserting a disclaimer block, separator, and footer link in one call.
Applications
🚀 Common Use Cases
Form disclaimers — insert legal text or helper notes immediately after a form section.
Horizontal rules — add <hr> separators after content blocks.
Error messages — show validation feedback as a sibling below the invalid field wrapper.
Read-more links — append a “Continue reading” link after article excerpts.
Relocate elements — move an existing banner or widget to follow a heading.
Dynamic labels — use the callback form to insert badges showing each element’s class name.
🧠 How .after() Inserts Content
1
Match anchor elements
jQuery collection points at elements that will stay in place.
Select
2
Parse or accept content
HTML strings parsed; DOM nodes and jQuery objects inserted directly.
Content
3
Insert as next sibling
Content placed immediately after each matched element in the parent.
After
4
⬇
Return jQuery collection
Same anchor collection since jQuery 1.9 — ready for chaining.
Important
📝 Notes
Available since jQuery 1.0 — callback form added in jQuery 1.4.
Inserts as the next sibling; use .before() for the previous sibling.
Matched elements are unchanged — content goes outside, not inside.
Inserting after a single target moves existing nodes; multiple targets clone except last.
Do not pass HTML strings from untrusted user input — XSS risk.
.append() inserts inside as last child; .after() inserts as sibling below.
Since jQuery 1.9, .after() always returns the original matched set.
Multiple arguments supported: .after(a, b, c).
Compatibility
Browser Support
.after() has been part of jQuery since 1.0+, with the callback form since 1.4+. It relies on standard DOM insertBefore operations on the parent node. 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 .after()
Universal sibling insertion API across jQuery 1.x, 2.x, 3.x, and 4.x. No browser-specific polyfills required — jQuery normalizes next-sibling insertion. Pair with .before() for above/below sibling 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
.after()Universal
Bottom line: Default choice for inserting content immediately after matched elements.
Wrap Up
Conclusion
The jQuery .after() method inserts content as the next sibling after 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 .before() when content belongs above the element, and .insertAfter() when content-first syntax reads better. For content inside a container, use .append() or .prepend() instead. Next up: the mirror sibling method .before().
Use .after() for disclaimers, separators, and follow-up blocks below an element
Create elements with .text() for safe dynamic error messages
Use the callback form for per-element suffixes or class-name badges
Prefer .insertAfter() when building content before choosing the anchor
Check whether content belongs inside (.append) or outside (.after)
❌ Don’t
Use .after() when content should be a child inside the element
Pass untrusted HTML strings to .after() (XSS risk)
Confuse .after() with .append() (sibling vs child)
Assume inserting always clones — single target moves existing nodes
Call .after() on elements without a parent (no effect since 1.9)
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about .after()
The insert-below-sibling API — next sibling insertion made easy.
6
Core concepts
↓01
Next
Sibling
Insert
<>02
HTML
Or DOM
Content
↑03
vs before
Prev sibling
Compare
fn04
Callback
Since 1.4
Dynamic
↔05
vs append
Inside
Scope
1.906
Returns
Original set
Chain
❓ Frequently Asked Questions
.after() inserts the specified content immediately after each element in the matched set — as a sibling, not inside the element. It accepts HTML strings, DOM elements, text nodes, arrays, jQuery objects, multiple arguments, or a callback function (since 1.4). Returns the same jQuery collection for chaining. Available since jQuery 1.0.
.after() inserts content as the next sibling after each matched element. .before() inserts content as the previous sibling before each matched element. Both operate outside the matched element; neither adds children inside it.
Both insert content after target elements. With .after(), the matched element is the anchor: $('p').after('<hr>'). With .insertAfter(), the content comes first: $('<hr>').insertAfter('p'). Same DOM result, reversed syntax — like .append() vs .appendTo().
.after() inserts siblings outside and below the matched element. .append() inserts children inside the matched element as the last child. Use after for separators, disclaimers, or follow-up blocks; use append to fill a container.
When you insert an existing DOM element after a single target, jQuery moves it (not clones). If you call .after() on multiple matched elements, jQuery clones the inserted element for every target except the last — the original moves to the final target.
Since jQuery 1.4, yes. .after(function(index)) runs once per matched element. Return an HTML string, DOM node, or jQuery object to insert after that element. Inside the function, this refers to the current DOM element. Since jQuery 1.10, a two-argument form also receives the old HTML value.
Did you know?
jQuery’s .after() and .before() have been sibling-insertion pairs since version 1.0, while .insertAfter() and .insertBefore() offer the same behavior with content-first syntax — mirroring the .append() / .appendTo() pattern. Before jQuery 1.9, calling .after() on disconnected nodes could return an unpredictable collection; modern jQuery always returns the original matched set, making method chaining reliable again.