jQuery after() Method

Last Updated:

jQuery after() Method

The jQuery after() method inserts specified content after the selected elements.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery after() Method</h1> <p>My Name is Jade</p> <button>What Jade Like</button> <script> $(document).ready(function(){ $("button").click(function(){ $("p").after("<p>I like programming</p>"); }); }); </script> </body> </html>

Syntax

$(selector).after(content); // or $(selector).after(func);

Parameter Values

Value Explanation
content Specifies the content to insert after the target selector.
Possible values:
  • HTML string
  • DOM element
  • Text node
  • Array of elements and text nodes
  • jQuery object
func(index, htmlString) Specifies a function that returns the content to insert after the target selector.
Parameter Values:
  • index - Receives the index position of the element in the set. Optional.
  • htmlString - Receives the old HTML value. Optional.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
after()YesYesYesYesYesYesYesYesYesYesYesYesYes

after() using Function

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery after() Method</h1> <p>My Name is Jade</p> <button>What Jade Like</button> <script> $(document).ready(function(){ $("button").click(function(){ $("p").after(function(){ return "<p>I like programming</p>"; }); }); }); </script> </body> </html>

Share this Page

Meet the Author