jQuery Document Operation - insertAfter() Method

Example

Insert a span element after each p element:

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

Try it yourself

Definition and usage

The insertAfter() method inserts HTML tags or existing elements after the selected element.

Note:If this method is used for existing elements, these elements will be moved from their current position and then added after the selected element.

Syntax

$(content).insertAfter(selector)
Parameters Description
content

Required. Specifies the content to be inserted. Possible values:

  • Selector expression
  • HTML tag
selector Required. Specifies where to insert the selected element.

More examples

Inserting an existing element
How to use the insertAfter() method to insert an existing element after each selected element.