Home >>jQuery Tutorial >jQuery insertAfter() Method
jQuery insertAfter() methodis used to inserts HTML elements after the selected elements.
Syntax:$(content).insertAfter(selector)
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 |
<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>
This is a first paragraph.
This is second paragraph.