The insertAfter() method in JQuery is used to insert HTML element right 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://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"> </script>
<script>
$('button').click( function() {
$('<p> This is a new paragraph </p>').insertAfter('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> This is a new paragraph </p>').insertAfter('p');
});So, on button click, the insertAfter() function is called,
$('<p> This is a new paragraph </p>').insertAfter('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.
1.png)