.after(content) inserts content immediately after each matched element as a sibling (since jQuery 1.0). It returns the original jQuery set for chaining.
Remember
$(target).after(content)
$(target).after("<b>Hi</b>")
$(target).after(domNode)
$(target).after($other)
// Sibling AFTER target — not inside it
// Same job as insertAfter, reversed syntax
Select the anchor element(s), then pass what should appear right after them.
Select the target(s): $("p"), $(".item"), etc.
Call .after(content) with HTML, a node, a jQuery object, or several arguments.
Or pass a function (1.4+) that returns content for each matched element.
Chain further methods on the same original selection if needed.
Piece
Required?
Role
Matched set
Yes
Anchor elements (must have a parent)
content
Yes*
HTML / node / array / jQuery object
function(index[, html])
Alt
Per-element content (1.4 / 1.10+)
Return value
—
Original jQuery set (1.9+ always)
Pseudocode
Pseudocode
function after(elements, content):
for each element in elements:
if element has no parent: skip
node = build(content) // or clone for extra targets
insert node as next sibling after element
return original elements
Reference
Cheat Sheet
Keep these facts handy while inserting siblings.
Topic
Detail
Syntax
.after(content [, content…]) or .after(fn)
Since
1.0 (callback 1.4; index+html callback 1.10)
Where
Next sibling (outside the element)
Move vs clone
Move for one target; clones for multiple
Disconnected node
No effect (jQuery 1.9+)
Returns
Original set (chainable)
Try it
Live Preview
Pick a demo and insert content after the sample paragraph.
Browser demo of .after() — result shows a simplified DOM sketch.
Result
<p>I would like to say:</p>
<b>Hello</b>
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Insert HTML After a Paragraph
Official style: pass an HTML string as the next sibling.
insertAfter: content first — $(content).insertAfter(target).
DOM ends up the same for one target.
Pick the form that reads clearest in your chain.
Edge Cases & Pitfalls
Watch these when inserting siblings with .after().
xss
Untrusted HTML is dangerous
HTML strings can run scripts. Treat user input as unsafe unless sanitized.
clone
Multiple targets clone content
Existing nodes are cloned for every match except the last. Event handlers on moved nodes need care — use .clone(true) when you need data/events copied on purpose.
parent
No parent → no effect (1.9+)
Calling .after() on a disconnected node does nothing and still returns the original set.
inside
Not the same as .append()
Need content inside the element? Use append/prepend, not after/before.
Compatibility
Browser Support
.after() has shipped since jQuery 1.0 (callback form since 1.4). It works in all modern browsers with jQuery loaded. Behavior for disconnected nodes stabilized in jQuery 1.9.
✓ jQuery 1.0+
.after()
Supported everywhere jQuery DOM APIs run in the browser. Insert siblings after matched elements.
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
.after()Excellent
Bottom line: Call $(target).after(content) for next-sibling insertion. Prefer insertAfter when content-first chaining reads better.
Analysis
Performance Notes
Approach
Cost
Best for
.after(html)
Parse + insert
Simple sibling inserts
.after($nodes)
Move / clone
Reordering existing nodes
Many targets + clones
Higher
Batch or build a fragment first
For lots of inserts, build a DocumentFragment (or one jQuery collection) and insert once when possible — fewer reflows than many tiny .after() calls.
Remember
Key Takeaways
Role: insert content as the next sibling after each match.
Syntax twin:insertAfter does the same job reversed.
Move/clone: one target moves; many targets clone.
Safety: never insert unsanitized user HTML.
One line:$(target).after(content) adds a next sibling — outside the element, not inside it.
Frequently Asked Questions
.after() inserts content immediately after each matched element as a next sibling (not inside it). It accepts HTML strings, DOM/text nodes, arrays, jQuery objects, multiple arguments, or a callback (since 1.4). Returns the original jQuery set for chaining.
.after() inserts as the next sibling; .before() inserts as the previous sibling. Neither adds children inside the matched element.
Same DOM result, reversed syntax: $(target).after(content) vs $(content).insertAfter(target) — like append vs appendTo.
.after() adds a sibling outside the element. .append() adds a child inside the element as the last child.
For a single target, an existing DOM node is moved. For multiple targets, jQuery clones for each target except the last (the original moves to the last target).
No. Like other HTML-accepting APIs, .after() can run script from untrusted strings. Never insert raw user input, URL params, or cookies without sanitizing.