The after() method in JQuery is used to insert a content after an HTML element.
<html> <head> <title> My First Programme </title> </head> <body> <h1> JQuery </h1> <p>New Code</p> <button> Click Here </button> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> <script> $('button').click( function() { $('p').after("<p> This is a new paragraph </p>"); }); </script> </body> </html>
So, in the above code, we have to to add a new content <p> This is a new paragraph </p>, right after the <p> element,
<p>New Code</p>
And we have done it using the JQuery statement,
$('button').click( function() { $('p').after("<p> This is a new paragraph </p>"); });
So, on button click, the after() function is called,
$('p').after("<p> This is a new paragraph </p>");
And the new content,
<p> This is a new paragraph </p>
Is added after,
<p>New Code</p>
Just note that This is a new paragraph is a new element that is added after the <p> element.