The insertAfter() is an inbuilt method in jQuery which is used to insert some HTML content after a specified element. The HTML content will be inserted after each occurrence of the specified element.
Syntax:
$(content).insertAfter(target)
Here the “content” is the HTML content which is to be inserted after the specified target.
Parameters: It takes a parameter “target” which is target after which the content is to be inserted.
Return Value: It doesn’t return any value.
Code #1:
<!DOCTYPE html> <html> <head> <script </script> <script> $(document).ready(function() { $("div").click(function() { // insertAfter $("<p>You should follow GeeksForGeeks</p>").insertAfter("p"); }); }); </script> </head> <body> <p>To learn jQuery : </p> <div>Click here to complete</div> </body> </html> |
Output:
Before clicking the div content-
To learn jQuery : Click here to complete
After clicking the div content-
To learn jQuery : You should follow GeeksForGeeks Click here to complete
Code #2:
<!DOCTYPE html> <html> <head> <script </script> <script> $(document).ready(function() { $("div").click(function() { // insertAfter $("<p>You should follow GeeksForGeeks</p>").insertAfter("p"); }); }); </script> </head> <body> <p>To learn jQuery : </p> <p> To learn coding : </p> <div>Click here to complete</div> </body> </html> |
Output:
Before clicking the div content-
To learn jQuery : To learn coding : Click here to complete
After clicking the div content-
To learn jQuery : You should follow GeeksForGeeks To learn coding : You should follow GeeksForGeeks Click here to complete
Recommended Posts:
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | prepend() with Examples
- jQuery | dblclick() with Examples
- jQuery | offset() with Examples
- jQuery | children() with Examples
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- jQuery | focusin() with Examples
- jQuery | Animation, Slide methods with Examples
- jQuery | change() with Examples
- jQuery | filter() with Examples
- jQuery | height() and innerHeight() with Examples
- jQuery | eq() with Examples
- jQuery | empty() with Examples
- jQuery | not() method with Examples
- jQuery | first() with Examples
- jQuery | parent() & parents() with Examples
- jQuery | noConflict() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


