---
title: "Difference between after() and insertAfter() methods in jQuery"  
description: "Difference between after() and insertAfter() methods in jQuery"  
author: "Ethan Karla"  
published: 2021-07-29  
updated: 2023-06-14  
canonical: https://www.mindstick.com/forum/156672/difference-between-after-and-insertafter-methods-in-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Difference between after() and insertAfter() methods in jQuery

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between after() and insertAfter() [methods in jQuery](https://www.mindstick.com/forum/159116/explain-the-difference-between-fadeout-and-hide-methods-in-jquery)?

\

## Replies

### Reply by Aryan Kumar

The after() and insertAfter() [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) in jQuery are both used to insert content after an element. However, there is a subtle difference between the two methods.

The after() method takes a selector as its argument. The content that is inserted will be inserted after each element that matches the selector. For example, the following code will insert a new paragraph element after each <div> element:

Code snippet

```plaintext
$("div").after("<p>This is a new paragraph.</p>");
```

The insertAfter() method, on the other hand, takes the content that is to be inserted as its argument. The content will be inserted after the element that is passed to the method. For example, the following code will insert a new paragraph element after the first <div> element:

Code snippet

```plaintext
$("#firstDiv").insertAfter("<p>This is a new paragraph.</p>");
```

In general, the after() method is more flexible than the insertAfter() method. However, the insertAfter() method can be used when the content that is to be inserted is not known at the time the code is written.

Here is a table that summarizes the differences between the after() and insertAfter() methods:

| Method | Argument | Inserts content |
| --- | --- | --- |
| after() | Selector | After each element that matches the selector |
| insertAfter() | Content | After the element that is passed to the method |

drive_spreadsheetExport to Sheets

I hope this helps! Let me know if you have any other questions.


---

Original Source: https://www.mindstick.com/forum/156672/difference-between-after-and-insertafter-methods-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
