The insertAfter method

The insertAfter method adds text after the given element. There is also a after method that works in a similar way.

Syntax

Insert text after an element:

javascript$(text).insertAfter(selector);

The content can be not only plain text, but also a DOM element, selector, array of elements, string or jQuery object.

Example

Let's insert text with tags after the given paragraph:

html<p id="test">paragraph indent indention indentation indenture rubric</p>
javascript$('<p>!!!</p>').insertAfter('#test');

HTML the code will look like this:

html<p id="test">paragraph indent indention indentation indenture rubric</p><p>!!!</p>

See also