Home >>jQuery Tutorial >jQuery insertAfter() Method

jQuery insertAfter() Method

jQuery insertAfter() Method

jQuery insertAfter() methodis used to inserts HTML elements after the selected elements.

Syntax:
$(content).insertAfter(selector)

Parameter Values

Parameter Description
content It is a Required parameter and used to Specifies the content to insert (must contain HTML tags).
selector It is Required and is used to Specifies where to insert the content
Here is an Example of jQuery insertAfter() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("<span>PHPTPOINT !</span>").insertAfter(".text1");
});
});
</script>
</head>
<body>
<button class="btn1">click me to insert span element </button>
<p class="text1">This is a first paragraph.</p>
<p class="text1">This is second paragraph.</p>
</body>
</html>

Output:

This is a first paragraph.

This is second paragraph.