jQuery after() Method (original) (raw)
Last Updated : 27 Oct, 2022
The after() method is an inbuilt function in jQuery which is used to insert content, specified by the parameter for each selected element in the set of matched elements.
Syntax:
$(selector).after(A);
Parameter: It accepts a parameter "A" which is either a content or function passed to the method.
Return Value: It returns the selected element with the modification.
Example 1: In the below example, element is passing to the method which will get added after the selected element.
HTML `
I would like to say:
<script>
$("p").after("<b><h2>Hello Geeks</h2></b>");
</script>
`
Output:
Example 2: In the below code, the function is passed to the method that will work after the selected element.
HTML `
This is first paragraph !!!
This is the second paragraph !!!
<script>
$("p").after(function () {
return "<div>" + "GeeksforGeeks" + "</div>";
});
</script>
`
Output: