Home >>jQuery Tutorial >jQuery after() Method

jQuery after() Method

jQuery after() Method

jQuery after() method in jQuery is used to inserts specified content afterselecting the elements.

Syntax:
$(selector).after(content,function(index))

Parameter Values

Parameter Description
content It is a Required parameter used to insert the specifies content (can contain HTML tags)

Possible values:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index) It is used to returns the specifies content to insert
  • index – used to Returns the set of index position in the element
Here is an Example of jQuery after() 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(){
$(".txt").after("<p>PHPTPOINT</p>");
});
});
</script>
</head>
<body>
<button class="btn1">click to insert content</button>
<p class="txt">This is a Phptpoint.</p>
<p class="txt">learn here</p>
</body>
</html>

Output:

This is a Phptpoint.

learn here