jQuery after() Method

The jQuery after() method can be used to add the specified content after the selected element. It inserts the content after the element and not inside the selected element.

jQuery after() Method

Syntax

The syntax of this method is given below:-

Syntax
$(selector).after(content)
Syntax
$(selector).after(function(index))

Description of the Parameters

The description of these parameters is given below.

Parameter Name Description
selector Specify the element to select and add after content to it. Use tag name, class name, or id of the elements to select. It is a required field.
content Specify the content to add after the selected element. It is a required field.
index It returns the index position of the element.

jQuery after() Method to Add Content

If you want to insert or add the content after the selected element, you have to use the method as given below. The example adds the specified content after the element and not inside the element.

Example

Test it Live

Output

This is my paragraph.


The above example contains the button and the paragraph element. When you click the button given above, the em element gets added after the p element. You can click the above button for more than one time to add the specified content.

Pass Function to Add Content

You can also pass the function to the jQuery after() method to add content after the element. Use the example given below to pass the function and insert the content.

Example

Test it Live

Output

This is my paragraph.


The above example contains the paragraph and the b element. You have to click the button given above to add the content after the selected element.

You may also like to read

I hope you like this tutorial on jQuery after() method. If you have any queries regarding the tutorial, please comment below.

References