jQuery Document Manipulation - after() Method

Example

Insert content after each p element:

$("button").click(function(){
  $("p").after("<p>Hello world!</p>");
});

Try It Yourself

Definition and Usage

The after() method inserts specified content after the selected element.

Syntax

$("selector").after(content)
Parameter Description
content Required. Specifies the content to be inserted (can include HTML tags).

Inserting Content with a Function

Use a function to insert specified content after the selected element.

Syntax

$("selector").after(function(index))

Try It Yourself

Parameter Description
function(index)

Required. Specifies the function to return the content to be inserted.

  • index - Optional. Receives the index position of the selector.